<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>👍python内置函数 | iworkh blog</title>
  
    <meta name="keywords" content=" func ">
  
  <meta name="description" content="👍python内置函数 | iworkh blog">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<meta name="description" content="个人简介沐雨云楼，程序员一名。 喜欢研究技术，主要从事JAVA、微服务、大数据领域。 联系方式 QQ : 157162006 邮箱 :157162006@qq.com">
<meta property="og:type" content="website">
<meta property="og:title" content="关于">
<meta property="og:url" content="https://iworkh.gitee.io/blog/about/index.html">
<meta property="og:site_name" content="iworkh blog">
<meta property="og:description" content="个人简介沐雨云楼，程序员一名。 喜欢研究技术，主要从事JAVA、微服务、大数据领域。 联系方式 QQ : 157162006 邮箱 :157162006@qq.com">
<meta property="og:locale" content="zh_CN">
<meta property="article:published_time" content="2020-05-17T07:22:16.000Z">
<meta property="article:modified_time" content="2020-09-12T13:21:47.523Z">
<meta property="article:author" content="沐雨云楼">
<meta property="article:tag" content="iworkh">
<meta property="article:tag" content="沐雨云楼">
<meta property="article:tag" content="blog">
<meta name="twitter:card" content="summary">


<link rel="icon" href="/blog/img/iwork.svg">

<link href="/blog/css/style.css?v=1.0.1" rel="stylesheet">

<link href="/blog/css/hl_theme/atom-light.css?v=1.0.1" rel="stylesheet">

<link href="//cdn.bootcdn.net/ajax/libs/animate.css/4.1.0/animate.min.css" rel="stylesheet">
<link href="//cdn.bootcdn.net/ajax/libs/font-awesome/5.13.0/js/fontawesome.min.js" rel="stylesheet">

<script src="//cdn.bootcdn.net/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script src="/blog/js/jquery.autocomplete.min.js?v=1.0.1" ></script>
<script src="/blog/js/titleTip.js?v=1.0.1" ></script>

<script src="//cdn.bootcdn.net/ajax/libs/highlight.js/10.0.3/highlight.min.js"></script>
<script>
    hljs.initHighlightingOnLoad();
</script>

<script src="//cdn.bootcdn.net/ajax/libs/nprogress/0.2.0/nprogress.min.js"></script>



<script src="//cdn.bootcdn.net/ajax/libs/jquery-cookie/1.4.1/jquery.cookie.min.js" ></script>

<script src="/blog/js/iconfont.js?v=1.0.1" ></script>

<meta name="generator" content="Hexo 4.2.1"></head>
<div style="display: none">
  <input class="theme_disqus_on" value="false">
  <input class="theme_preload_comment" value="false">
  <input class="theme_blog_path" value="/blog">
</div>




<body>
<aside class="nav">
    <div class="nav-left">
        <a href="/blog/" class="avatar_target">
    <img class="avatar" src="/blog/img/iwork.svg" />
</a>
<div class="author">
    <span>沐雨云楼</span>
</div>

<div class="icon">
    
        
        <a title="github" href="https://gitee.com/iworkh" target="_blank">
            
                <svg class="iconfont-svg" aria-hidden="true">
                    <use xlink:href="#icon-github"></use>
                </svg>
            
        </a>
        
    
        
        <a title="csdn" href="https://blog.csdn.net/u011622109" target="_blank">
            
                <svg class="iconfont-svg" aria-hidden="true">
                    <use xlink:href="#icon-csdn"></use>
                </svg>
            
        </a>
        
    
        
        <a title="email" href="mailto:157162006@qq.com" target="_blank">
            
                <svg class="iconfont-svg" aria-hidden="true">
                    <use xlink:href="#icon-email"></use>
                </svg>
            
        </a>
        
    
        
        <a title="qq" href="http://wpa.qq.com/msgrd?v=3&uin=157162006&site=qq&menu=yes" target="_blank">
            
                <svg class="iconfont-svg" aria-hidden="true">
                    <use xlink:href="#icon-qq"></use>
                </svg>
            
        </a>
        
    
        
        <a title="kugou" href="https://www.kugou.com/" target="_blank">
            
                <svg class="iconfont-svg" aria-hidden="true">
                    <use xlink:href="#icon-kugou"></use>
                </svg>
            
        </a>
        
    
        
        <a title="neteasemusic" href="https://music.163.com/" target="_blank">
            
                <svg class="iconfont-svg" aria-hidden="true">
                    <use xlink:href="#icon-neteasemusic"></use>
                </svg>
            
        </a>
        
    
</div>



<a class="more-menus">更多菜单</a>


<ul>
    <li><div class="all active">全部文章<small>(85)</small></div></li>
    
        
            
            <li><div data-rel="手册"><i class="fold iconfont icon-right"></i>手册<small>(2)</small></div>
                
                    <ul class="sub hide">
                        
                        <li><div data-rel="iworkh">iworkh<small>(1)</small></div>
                            
                        </li>
                            
                        <li><div data-rel="pgmanor">pgmanor<small>(1)</small></div>
                            
                        </li>
                            
                    </ul>
                
            </li>
            
        
    
        
            
            <li><div data-rel="工具"><i class="fold iconfont icon-right"></i>工具<small>(16)</small></div>
                
                    <ul class="sub hide">
                        
                        <li><div data-rel="git">git<small>(2)</small></div>
                            
                        </li>
                            
                        <li><div data-rel="github">github<small>(1)</small></div>
                            
                        </li>
                            
                        <li><div data-rel="hexo">hexo<small>(1)</small></div>
                            
                        </li>
                            
                        <li><div data-rel="idea">idea<small>(2)</small></div>
                            
                        </li>
                            
                        <li><div data-rel="markdowm">markdowm<small>(1)</small></div>
                            
                        </li>
                            
                        <li><div data-rel="maven">maven<small>(1)</small></div>
                            
                        </li>
                            
                        <li><div data-rel="有道云">有道云<small>(1)</small></div>
                            
                        </li>
                            
                    </ul>
                
            </li>
            
        
    
        
            
            <li><div data-rel="java"><i class="fold iconfont icon-right"></i>java<small>(20)</small></div>
                
                    <ul class="sub hide">
                        
                        <li><div data-rel="dao">dao<small>(6)</small></div>
                            
                        </li>
                            
                        <li><div data-rel="jvm">jvm<small>(1)</small></div>
                            
                        </li>
                            
                        <li><div data-rel="test">test<small>(5)</small></div>
                            
                        </li>
                            
                        <li><div data-rel="tools">tools<small>(3)</small></div>
                            
                        </li>
                            
                        <li><div data-rel="并发">并发<small>(1)</small></div>
                            
                        </li>
                            
                    </ul>
                
            </li>
            
        
    
        
            
            <li><div data-rel="微服务"><i class="fold iconfont icon-right"></i>微服务<small>(6)</small></div>
                
                    <ul class="sub hide">
                        
                        <li><div data-rel="spring">spring<small>(2)</small></div>
                            
                        </li>
                            
                        <li><div data-rel="springboot">springboot<small>(3)</small></div>
                            
                        </li>
                            
                    </ul>
                
            </li>
            
        
    
        
            
            <li><div data-rel="架构">架构<small>(2)</small></div>
                
            </li>
            
        
    
        
            
            <li><div data-rel="大数据"><i class="fold iconfont icon-right"></i>大数据<small>(4)</small></div>
                
                    <ul class="sub hide">
                        
                        <li><div data-rel="hadoop">hadoop<small>(1)</small></div>
                            
                        </li>
                            
                        <li><div data-rel="spark">spark<small>(3)</small></div>
                            
                        </li>
                            
                    </ul>
                
            </li>
            
        
    
        
            
            <li><div data-rel="web"><i class="fold iconfont icon-right"></i>web<small>(3)</small></div>
                
                    <ul class="sub hide">
                        
                        <li><div data-rel="vue">vue<small>(2)</small></div>
                            
                        </li>
                            
                    </ul>
                
            </li>
            
        
    
        
            
            <li><div data-rel="db"><i class="fold iconfont icon-right"></i>db<small>(4)</small></div>
                
                    <ul class="sub hide">
                        
                        <li><div data-rel="mysql">mysql<small>(3)</small></div>
                            
                        </li>
                            
                        <li><div data-rel="redis">redis<small>(1)</small></div>
                            
                        </li>
                            
                    </ul>
                
            </li>
            
        
    
        
            
            <li><div data-rel="ai">ai<small>(4)</small></div>
                
            </li>
            
        
    
        
            
            <li><div data-rel="python"><i class="fold iconfont icon-right"></i>python<small>(8)</small></div>
                
                    <ul class="sub hide">
                        
                        <li><div data-rel="tornado">tornado<small>(3)</small></div>
                            
                        </li>
                            
                    </ul>
                
            </li>
            
        
    
        
            
            <li><div data-rel="linux"><i class="fold iconfont icon-right"></i>linux<small>(2)</small></div>
                
                    <ul class="sub hide">
                        
                        <li><div data-rel="docker">docker<small>(1)</small></div>
                            
                        </li>
                            
                        <li><div data-rel="nginx">nginx<small>(1)</small></div>
                            
                        </li>
                            
                    </ul>
                
            </li>
            
        
    
        
            
            <li><div data-rel="windows">windows<small>(3)</small></div>
                
            </li>
            
        
    
        
            
            <li><div data-rel="结构和算法">结构和算法<small>(8)</small></div>
                
            </li>
            
        
    
        
            
            <li><div data-rel="面试">面试<small>(2)</small></div>
                
            </li>
            
        
    
        
            
            <li><div data-rel="其他">其他<small>(1)</small></div>
                
            </li>
            
        
    
        
            
        
    
        
            
        
    
        
            
        
    
        
            
        
    
        
            
        
    
        
            
        
    
        
            
        
    
        
            
        
    
        
            
        
    
        
            
        
    
        
            
        
    
        
            
        
    
        
            
        
    
        
            
        
    
        
            
        
    
        
            
        
    
        
            
        
    
        
            
        
    
        
            
        
    
        
            
        
    
        
            
        
    
        
            
        
    
        
            
        
    
        
            
        
    
</ul>
<div class="left-bottom">
    <div class="menus">
    
    
    
    <a class="dynamic-menu " target="_blank"  href="https://pgmanor.gitee.io/blog/">pgmanor</a>
    
    
    <a class="dynamic-menu " target="_blank"  href="https://www.iworkh.com/manualIt/Category/scopeDev/">iworkh</a>
    
    
    <a class="dynamic-menu " target="_blank"  href="https://gitee.com/iworkh">gitee</a>
    
    </div>
    <div><a class="about  hasFriend  site_url"  href="/blog/about">关于</a><a style="width: 50%"  class="friends">友链</a></div>
</div>
<input type="hidden" id="iworkh_site_posts_number" value="85">
<input type="hidden" id="iworkh_site_word_count" value="197.8k">
<div style="display: none">
    <span id="busuanzi_value_site_uv"></span>
    <span id="busuanzi_value_site_pv"></span>
</div>

    </div>
    <div class="nav-right">
        <div class="friends-area">
    <div class="friends-title">
        友情链接
        <i class="back-title-list"></i>
    </div>
    <div class="friends-content">
        <ul>
            
            <li><a target="_blank" href="https://www.iworkh.com">iworkh</a></li>
            
            <li><a target="_blank" href="https://www.iworkh.com/download/share/">下载地址</a></li>
            
            <li><a target="_blank" href="http://yelog.org/">叶落阁</a></li>
            
        </ul>
    </div>
</div>
        <div class="title-list">
    <form onkeydown="if(event.keyCode === 13){return false;}">
        <input id="local-search-input" class="search" type="text" placeholder="in: 开头全文搜索" />
        <i class="cross"></i>
        <span>
            <label for="tagswitch">T:</label>
            <input id="tagswitch" type="checkbox" style="display: none" />
            <i id="tagsWitchIcon"></i>
        </span>
    </form>
    <div class="tags-list">
    
    <li class="article-tag-list-item">
        <a class="color3">ai</a>
    </li>
    
    <li class="article-tag-list-item">
        <a class="color5">attr</a>
    </li>
    
    <li class="article-tag-list-item">
        <a class="color1">aysnc</a>
    </li>
    
    <li class="article-tag-list-item">
        <a class="color3">beanmap</a>
    </li>
    
    <li class="article-tag-list-item">
        <a class="color1">bigdecimal</a>
    </li>
    
    <li class="article-tag-list-item">
        <a class="color5">blog</a>
    </li>
    
    <li class="article-tag-list-item">
        <a class="color2">chrome</a>
    </li>
    
    <li class="article-tag-list-item">
        <a class="color5">dict</a>
    </li>
    
    <li class="article-tag-list-item">
        <a class="color4">dll</a>
    </li>
    
    <li class="article-tag-list-item">
        <a class="color2">docker</a>
    </li>
    
    <li class="article-tag-list-item">
        <a class="color2">domain</a>
    </li>
    
    <li class="article-tag-list-item">
        <a class="color4">fastjson</a>
    </li>
    
    <li class="article-tag-list-item">
        <a class="color5">func</a>
    </li>
    
    <li class="article-tag-list-item">
        <a class="color4">git</a>
    </li>
    
    <li class="article-tag-list-item">
        <a class="color2">github</a>
    </li>
    
    <li class="article-tag-list-item">
        <a class="color2">hadoop</a>
    </li>
    
    <li class="article-tag-list-item">
        <a class="color5">hexo</a>
    </li>
    
    <li class="article-tag-list-item">
        <a class="color5">idea</a>
    </li>
    
    <li class="article-tag-list-item">
        <a class="color2">iworkh</a>
    </li>
    
    <li class="article-tag-list-item">
        <a class="color3">jackson</a>
    </li>
    
    <li class="article-tag-list-item">
        <a class="color5">java</a>
    </li>
    
    <li class="article-tag-list-item">
        <a class="color5">jdni</a>
    </li>
    
    <li class="article-tag-list-item">
        <a class="color2">jfinalshell</a>
    </li>
    
    <li class="article-tag-list-item">
        <a class="color2">joplin</a>
    </li>
    
    <li class="article-tag-list-item">
        <a class="color4">JPA</a>
    </li>
    
    <li class="article-tag-list-item">
        <a class="color5">lock</a>
    </li>
    
    <li class="article-tag-list-item">
        <a class="color4">markdowm</a>
    </li>
    
    <li class="article-tag-list-item">
        <a class="color1">maven</a>
    </li>
    
    <li class="article-tag-list-item">
        <a class="color5">mock</a>
    </li>
    
    <li class="article-tag-list-item">
        <a class="color3">mq</a>
    </li>
    
    <li class="article-tag-list-item">
        <a class="color1">mycat</a>
    </li>
    
    <li class="article-tag-list-item">
        <a class="color1">mysql</a>
    </li>
    
    <li class="article-tag-list-item">
        <a class="color1">nginx</a>
    </li>
    
    <li class="article-tag-list-item">
        <a class="color4">notebook</a>
    </li>
    
    <li class="article-tag-list-item">
        <a class="color5">plan</a>
    </li>
    
    <li class="article-tag-list-item">
        <a class="color5">powermock</a>
    </li>
    
    <li class="article-tag-list-item">
        <a class="color2">python</a>
    </li>
    
    <li class="article-tag-list-item">
        <a class="color1">redis</a>
    </li>
    
    <li class="article-tag-list-item">
        <a class="color5">rest</a>
    </li>
    
    <li class="article-tag-list-item">
        <a class="color4">sharding-jdbc</a>
    </li>
    
    <li class="article-tag-list-item">
        <a class="color1">spark</a>
    </li>
    
    <li class="article-tag-list-item">
        <a class="color1">springboot</a>
    </li>
    
    <li class="article-tag-list-item">
        <a class="color5">test</a>
    </li>
    
    <li class="article-tag-list-item">
        <a class="color5">tool</a>
    </li>
    
    <li class="article-tag-list-item">
        <a class="color1">tools</a>
    </li>
    
    <li class="article-tag-list-item">
        <a class="color3">tornado</a>
    </li>
    
    <li class="article-tag-list-item">
        <a class="color4">transactional</a>
    </li>
    
    <li class="article-tag-list-item">
        <a class="color4">web</a>
    </li>
    
    <li class="article-tag-list-item">
        <a class="color3">windows</a>
    </li>
    
    <li class="article-tag-list-item">
        <a class="color3">wtforms</a>
    </li>
    
    <li class="article-tag-list-item">
        <a class="color5">zookeeper</a>
    </li>
    
    <li class="article-tag-list-item">
        <a class="color5">分库分表</a>
    </li>
    
    <li class="article-tag-list-item">
        <a class="color3">分页</a>
    </li>
    
    <li class="article-tag-list-item">
        <a class="color3">命令</a>
    </li>
    
    <li class="article-tag-list-item">
        <a class="color3">工具</a>
    </li>
    
    <li class="article-tag-list-item">
        <a class="color3">并发</a>
    </li>
    
    <li class="article-tag-list-item">
        <a class="color4">序列化</a>
    </li>
    
    <li class="article-tag-list-item">
        <a class="color4">微服务</a>
    </li>
    
    <li class="article-tag-list-item">
        <a class="color5">性能分析</a>
    </li>
    
    <li class="article-tag-list-item">
        <a class="color3">手册</a>
    </li>
    
    <li class="article-tag-list-item">
        <a class="color4">有道云</a>
    </li>
    
    <li class="article-tag-list-item">
        <a class="color3">标签</a>
    </li>
    
    <li class="article-tag-list-item">
        <a class="color3">模板</a>
    </li>
    
    <li class="article-tag-list-item">
        <a class="color5">百度云盘</a>
    </li>
    
    <li class="article-tag-list-item">
        <a class="color1">结构和算法</a>
    </li>
    
    <li class="article-tag-list-item">
        <a class="color3">计划</a>
    </li>
    
    <li class="article-tag-list-item">
        <a class="color3">迁移</a>
    </li>
    
    <li class="article-tag-list-item">
        <a class="color3">面试</a>
    </li>
    
    <div class="clearfix"></div>
</div>

    
    <div id="local-search-result">

    </div>
    
    <nav id="title-list-nav">
        
        <a id="top" class="手册 pgmanor "
           href="/blog/2020/12/15/redirect-to-pgmanor/"
           data-tag="迁移"
           data-author="沐雨云楼" >
            <span class="post-title" title="😘博客迁移">😘博客迁移</span>
            <span class="post-date" title="2020-12-15 23:47:55">2020/12/15</span>
        </a>
        
        <a id="top" class="手册 iworkh "
           href="/blog/2020/05/27/manual-iworkh/"
           data-tag="手册,iworkh"
           data-author="沐雨云楼" >
            <span class="post-title" title="iworkh所有手册">iworkh所有手册</span>
            <span class="post-date" title="2020-05-27 21:37:04">2020/05/27</span>
        </a>
        
        <a id="top" class="微服务 springboot "
           href="/blog/2020/06/27/spring_boot_all_resources/"
           data-tag="springboot"
           data-author="沐雨云楼" >
            <span class="post-title" title="Spring Boot全网优质教程汇总">Spring Boot全网优质教程汇总</span>
            <span class="post-date" title="2020-06-27 17:43:13">2020/06/27</span>
        </a>
        
        <a id="top" class="工具 "
           href="/blog/2020/06/22/baidu-pandisk-share/"
           data-tag="百度云盘"
           data-author="沐雨云楼" >
            <span class="post-title" title="百度云盘分享链接">百度云盘分享链接</span>
            <span class="post-date" title="2020-06-22 18:38:21">2020/06/22</span>
        </a>
        
        <a id="top" class="工具 "
           href="/blog/2020/06/21/tool_blogs_all/"
           data-tag="blog"
           data-author="沐雨云楼" >
            <span class="post-title" title="优质博客和文章">优质博客和文章</span>
            <span class="post-date" title="2020-06-21 20:02:14">2020/06/21</span>
        </a>
        
        <a id="top" class="java jvm "
           href="/blog/2020/06/04/java-online-analysis/"
           data-tag="性能分析"
           data-author="沐雨云楼" >
            <span class="post-title" title="JAVA线上故障排查全套路">JAVA线上故障排查全套路</span>
            <span class="post-date" title="2020-06-04 20:34:05">2020/06/04</span>
        </a>
        
        <a id="top" class="工具 idea "
           href="/blog/2020/05/31/jetbrains-idea/"
           data-tag="工具,idea"
           data-author="沐雨云楼" >
            <span class="post-title" title="idea使用技巧">idea使用技巧</span>
            <span class="post-date" title="2020-05-31 16:12:30">2020/05/31</span>
        </a>
        
        <a id="top" class="工具 有道云 "
           href="/blog/2020/05/18/youdao_config_edit/"
           data-tag="工具,有道云"
           data-author="沐雨云楼" >
            <span class="post-title" title="有道云配置修改">有道云配置修改</span>
            <span class="post-date" title="2020-05-18 21:37:04">2020/05/18</span>
        </a>
        
        <a id="top" class="web "
           href="/blog/2020/06/01/web-tools/"
           data-tag="web,tool"
           data-author="沐雨云楼" >
            <span class="post-title" title="前端常用工具">前端常用工具</span>
            <span class="post-date" title="2020-06-01 21:37:04">2020/06/01</span>
        </a>
        
        <a  class="工具 "
           href="/blog/2020/10/25/tool-linux-jfinalshell/"
           data-tag="jfinalshell"
           data-author="沐雨云楼" >
            <span class="post-title" title="linux连接工具jfinalshell">linux连接工具jfinalshell</span>
            <span class="post-date" title="2020-10-25 10:24:59">2020/10/25</span>
        </a>
        
        <a  class="微服务 springboot "
           href="/blog/2020/10/06/spring-boot-multi-profiles/"
           data-tag="springboot"
           data-author="沐雨云楼" >
            <span class="post-title" title="springboot多环境配置打包">springboot多环境配置打包</span>
            <span class="post-date" title="2020-10-06 21:36:42">2020/10/06</span>
        </a>
        
        <a  class="web vue "
           href="/blog/2020/10/06/vue_springboot_package_publish/"
           data-tag="maven"
           data-author="沐雨云楼" >
            <span class="post-title" title="vue+springboot打包发布">vue+springboot打包发布</span>
            <span class="post-date" title="2020-10-06 14:22:29">2020/10/06</span>
        </a>
        
        <a  class="java dao "
           href="/blog/2020/10/06/java-jpa-query/"
           data-tag="JPA"
           data-author="沐雨云楼" >
            <span class="post-title" title="JPA自定义sql">JPA自定义sql</span>
            <span class="post-date" title="2020-10-06 10:20:38">2020/10/06</span>
        </a>
        
        <a  class="微服务 spring "
           href="/blog/2020/10/03/spring-pageable/"
           data-tag="分页"
           data-author="沐雨云楼" >
            <span class="post-title" title="vue+springboot分页交互">vue+springboot分页交互</span>
            <span class="post-date" title="2020-10-03 11:08:21">2020/10/03</span>
        </a>
        
        <a  class="工具 "
           href="/blog/2020/10/02/chrome-plugin/"
           data-tag="chrome"
           data-author="沐雨云楼" >
            <span class="post-title" title="chrome插件">chrome插件</span>
            <span class="post-date" title="2020-10-02 10:11:31">2020/10/02</span>
        </a>
        
        <a  class="windows "
           href="/blog/2020/10/01/windows-less-dll/"
           data-tag="dll"
           data-author="沐雨云楼" >
            <span class="post-title" title="windows缺少dll">windows缺少dll</span>
            <span class="post-date" title="2020-10-01 20:22:28">2020/10/01</span>
        </a>
        
        <a  class="java "
           href="/blog/2020/09/13/java-base-bigdecimal/"
           data-tag="bigdecimal"
           data-author="沐雨云楼" >
            <span class="post-title" title="BigDecimal正确使用了吗?">BigDecimal正确使用了吗?</span>
            <span class="post-date" title="2020-09-13 10:28:54">2020/09/13</span>
        </a>
        
        <a  class="windows "
           href="/blog/2020/09/12/windows-dev-install/"
           data-tag="windows"
           data-author="沐雨云楼" >
            <span class="post-title" title="windows开发环境安装">windows开发环境安装</span>
            <span class="post-date" title="2020-09-12 21:39:01">2020/09/12</span>
        </a>
        
        <a  class="工具 "
           href="/blog/2020/09/06/tool-notebook-joplin/"
           data-tag="joplin"
           data-author="沐雨云楼" >
            <span class="post-title" title="joplin笔记">joplin笔记</span>
            <span class="post-date" title="2020-09-06 20:50:55">2020/09/06</span>
        </a>
        
        <a  class="web vue "
           href="/blog/2020/09/05/vue-element-admin/"
           data-tag="web"
           data-author="沐雨云楼" >
            <span class="post-title" title="vue element admin开发">vue element admin开发</span>
            <span class="post-date" title="2020-09-05 11:01:38">2020/09/05</span>
        </a>
        
        <a  class="工具 "
           href="/blog/2020/09/05/tool-notebook/"
           data-tag="notebook"
           data-author="沐雨云楼" >
            <span class="post-title" title="常见笔记软件">常见笔记软件</span>
            <span class="post-date" title="2020-09-05 10:54:34">2020/09/05</span>
        </a>
        
        <a  class="java dao "
           href="/blog/2020/08/30/java-dao-shardingSphere/"
           data-tag="sharding-jdbc"
           data-author="沐雨云楼" >
            <span class="post-title" title="分库分表中间件-ShardingSphere">分库分表中间件-ShardingSphere</span>
            <span class="post-date" title="2020-08-30 21:52:45">2020/08/30</span>
        </a>
        
        <a  class="java dao "
           href="/blog/2020/08/30/java-dao-mycat/"
           data-tag="mycat"
           data-author="沐雨云楼" >
            <span class="post-title" title="分库分表中间件-MyCat">分库分表中间件-MyCat</span>
            <span class="post-date" title="2020-08-30 15:01:59">2020/08/30</span>
        </a>
        
        <a  class="java dao "
           href="/blog/2020/08/30/java-dao-sharding-db/"
           data-tag="分库分表"
           data-author="沐雨云楼" >
            <span class="post-title" title="分库分表中间件-开源产品">分库分表中间件-开源产品</span>
            <span class="post-date" title="2020-08-30 09:37:18">2020/08/30</span>
        </a>
        
        <a  class="java dao "
           href="/blog/2020/08/29/java-jndi/"
           data-tag="jdni"
           data-author="沐雨云楼" >
            <span class="post-title" title="JNDI">JNDI</span>
            <span class="post-date" title="2020-08-29 17:12:03">2020/08/29</span>
        </a>
        
        <a  class="工具 git "
           href="/blog/2020/08/27/tool-git-setting/"
           data-tag="git"
           data-author="沐雨云楼" >
            <span class="post-title" title="git配置">git配置</span>
            <span class="post-date" title="2020-08-27 21:30:17">2020/08/27</span>
        </a>
        
        <a  class="java test "
           href="/blog/2020/08/23/java-powermock/"
           data-tag="powermock"
           data-author="沐雨云楼" >
            <span class="post-title" title="powermock测试框架">powermock测试框架</span>
            <span class="post-date" title="2020-08-23 12:45:17">2020/08/23</span>
        </a>
        
        <a  class="java test "
           href="/blog/2020/08/23/java-mockito/"
           data-tag="mock"
           data-author="沐雨云楼" >
            <span class="post-title" title="👍mockito测试框架">👍mockito测试框架</span>
            <span class="post-date" title="2020-08-23 10:45:17">2020/08/23</span>
        </a>
        
        <a  class="java test "
           href="/blog/2020/08/22/java-test-ng/"
           data-tag="test"
           data-author="沐雨云楼" >
            <span class="post-title" title="👍TestNG一篇足以">👍TestNG一篇足以</span>
            <span class="post-date" title="2020-08-22 18:37:28">2020/08/22</span>
        </a>
        
        <a  class="db mysql "
           href="/blog/2020/08/19/mysql-common-sql/"
           data-tag="mysql"
           data-author="沐雨云楼" >
            <span class="post-title" title="mysql常用sql">mysql常用sql</span>
            <span class="post-date" title="2020-08-19 21:30:00">2020/08/19</span>
        </a>
        
        <a  class="db mysql "
           href="/blog/2020/08/19/mysql-windows-zip-install/"
           data-tag="mysql"
           data-author="沐雨云楼" >
            <span class="post-title" title="mysql zip在windows上安装">mysql zip在windows上安装</span>
            <span class="post-date" title="2020-08-19 21:00:47">2020/08/19</span>
        </a>
        
        <a  class="工具 idea "
           href="/blog/2020/08/15/jetbrains-crack/"
           data-tag="工具,idea"
           data-author="沐雨云楼" >
            <span class="post-title" title="jetbrains全家桶破解">jetbrains全家桶破解</span>
            <span class="post-date" title="2020-08-15 19:22:33">2020/08/15</span>
        </a>
        
        <a  class="工具 git "
           href="/blog/2020/07/10/tool-git-error-name-too-long/"
           data-tag="git"
           data-author="沐雨云楼" >
            <span class="post-title" title="git文件名太长">git文件名太长</span>
            <span class="post-date" title="2020-07-10 12:03:02">2020/07/10</span>
        </a>
        
        <a  class="db mysql "
           href="/blog/2020/07/04/mysql-lock-unlock-table/"
           data-tag="lock"
           data-author="沐雨云楼" >
            <span class="post-title" title="mysql数据库锁查询和释放">mysql数据库锁查询和释放</span>
            <span class="post-date" title="2020-07-04 21:46:54">2020/07/04</span>
        </a>
        
        <a  class="结构和算法 "
           href="/blog/2020/07/04/data-structures-algorithms-sort/"
           data-tag="结构和算法"
           data-author="沐雨云楼" >
            <span class="post-title" title="数据结构和算法8-排序">数据结构和算法8-排序</span>
            <span class="post-date" title="2020-07-04 18:49:12">2020/07/04</span>
        </a>
        
        <a  class="结构和算法 "
           href="/blog/2020/07/04/data-structures-algorithms-search/"
           data-tag="结构和算法"
           data-author="沐雨云楼" >
            <span class="post-title" title="数据结构和算法7-搜索">数据结构和算法7-搜索</span>
            <span class="post-date" title="2020-07-04 17:48:19">2020/07/04</span>
        </a>
        
        <a  class="结构和算法 "
           href="/blog/2020/07/04/data-structures-algorithms-graph/"
           data-tag="结构和算法"
           data-author="沐雨云楼" >
            <span class="post-title" title="数据结构和算法6-非线性-图">数据结构和算法6-非线性-图</span>
            <span class="post-date" title="2020-07-04 16:09:47">2020/07/04</span>
        </a>
        
        <a  class="结构和算法 "
           href="/blog/2020/07/04/data-structures-algorithms-tree/"
           data-tag="结构和算法"
           data-author="沐雨云楼" >
            <span class="post-title" title="数据结构和算法5-非线性-树">数据结构和算法5-非线性-树</span>
            <span class="post-date" title="2020-07-04 15:09:47">2020/07/04</span>
        </a>
        
        <a  class="结构和算法 "
           href="/blog/2020/07/04/data-structures-algorithms-linear-queue/"
           data-tag="结构和算法"
           data-author="沐雨云楼" >
            <span class="post-title" title="数据结构和算法4-线性-队列">数据结构和算法4-线性-队列</span>
            <span class="post-date" title="2020-07-04 14:10:22">2020/07/04</span>
        </a>
        
        <a  class="结构和算法 "
           href="/blog/2020/07/04/data-structures-algorithms-linear-stack/"
           data-tag="结构和算法"
           data-author="沐雨云楼" >
            <span class="post-title" title="数据结构和算法3-线性-栈">数据结构和算法3-线性-栈</span>
            <span class="post-date" title="2020-07-04 13:00:17">2020/07/04</span>
        </a>
        
        <a  class="结构和算法 "
           href="/blog/2020/07/04/data-structures-algorithms-linear-list/"
           data-tag="结构和算法"
           data-author="沐雨云楼" >
            <span class="post-title" title="数据结构和算法2-线性-链">数据结构和算法2-线性-链</span>
            <span class="post-date" title="2020-07-04 11:32:12">2020/07/04</span>
        </a>
        
        <a  class="结构和算法 "
           href="/blog/2020/07/04/data-structures-algorithms-info/"
           data-tag="结构和算法"
           data-author="沐雨云楼" >
            <span class="post-title" title="数据结构和算法1-介绍">数据结构和算法1-介绍</span>
            <span class="post-date" title="2020-07-04 10:10:40">2020/07/04</span>
        </a>
        
        <a  class="大数据 spark "
           href="/blog/2020/06/30/spark-install-windows/"
           data-tag="spark"
           data-author="沐雨云楼" >
            <span class="post-title" title="spark开发环境搭建">spark开发环境搭建</span>
            <span class="post-date" title="2020-06-30 19:24:51">2020/06/30</span>
        </a>
        
        <a  class="大数据 hadoop "
           href="/blog/2020/06/30/hadoop-install-windows/"
           data-tag="hadoop"
           data-author="沐雨云楼" >
            <span class="post-title" title="hadoop开发环境搭建">hadoop开发环境搭建</span>
            <span class="post-date" title="2020-06-30 18:06:23">2020/06/30</span>
        </a>
        
        <a  class="java "
           href="/blog/2020/06/30/java-install-windows/"
           data-tag="java"
           data-author="沐雨云楼" >
            <span class="post-title" title="jdk开发环境搭建">jdk开发环境搭建</span>
            <span class="post-date" title="2020-06-30 15:09:34">2020/06/30</span>
        </a>
        
        <a  class="ai "
           href="/blog/2020/06/30/ai-python-spark-env/"
           data-tag="spark"
           data-author="沐雨云楼" >
            <span class="post-title" title="python spark开发环境搭建">python spark开发环境搭建</span>
            <span class="post-date" title="2020-06-30 12:14:04">2020/06/30</span>
        </a>
        
        <a  class="ai "
           href="/blog/2020/06/29/ai-jupyter-notebook/"
           data-tag="标签"
           data-author="沐雨云楼" >
            <span class="post-title" title="jupyter notebook">jupyter notebook</span>
            <span class="post-date" title="2020-06-29 12:29:36">2020/06/29</span>
        </a>
        
        <a  class="ai "
           href="/blog/2020/06/26/ai-python-tools/"
           data-tag="tools"
           data-author="沐雨云楼" >
            <span class="post-title" title="python和ai常用工具">python和ai常用工具</span>
            <span class="post-date" title="2020-06-26 09:55:24">2020/06/26</span>
        </a>
        
        <a  class="python "
           href="/blog/2020/06/25/python-tool-buildin-attr/"
           data-tag="attr"
           data-author="沐雨云楼" >
            <span class="post-title" title="👍python内置属性(魔法方法)">👍python内置属性(魔法方法)</span>
            <span class="post-date" title="2020-06-25 11:01:33">2020/06/25</span>
        </a>
        
        <a  class="python "
           href="/blog/2020/06/24/python-tool-buildin-func/"
           data-tag="func"
           data-author="沐雨云楼" >
            <span class="post-title" title="👍python内置函数">👍python内置函数</span>
            <span class="post-date" title="2020-06-24 18:31:59">2020/06/24</span>
        </a>
        
        <a  class="python "
           href="/blog/2020/06/24/python-tool-obj-dict/"
           data-tag="dict"
           data-author="沐雨云楼" >
            <span class="post-title" title="python对象与dict互转">python对象与dict互转</span>
            <span class="post-date" title="2020-06-24 18:15:03">2020/06/24</span>
        </a>
        
        <a  class="大数据 spark "
           href="/blog/2020/06/21/spark-version-3/"
           data-tag="spark"
           data-author="沐雨云楼" >
            <span class="post-title" title="spark3.0新特性">spark3.0新特性</span>
            <span class="post-date" title="2020-06-21 17:40:12">2020/06/21</span>
        </a>
        
        <a  class="java "
           href="/blog/2020/06/21/java-base-domain/"
           data-tag="domain"
           data-author="沐雨云楼" >
            <span class="post-title" title="VO DTO DO PO你都了解吗?">VO DTO DO PO你都了解吗?</span>
            <span class="post-date" title="2020-06-21 09:20:03">2020/06/21</span>
        </a>
        
        <a  class="大数据 spark "
           href="/blog/2020/06/20/spark-data-skew/"
           data-tag="spark"
           data-author="沐雨云楼" >
            <span class="post-title" title="spark数据倾斜及解决方案">spark数据倾斜及解决方案</span>
            <span class="post-date" title="2020-06-20 21:41:12">2020/06/20</span>
        </a>
        
        <a  class="linux nginx "
           href="/blog/2020/06/20/nginx-fast/"
           data-tag="nginx"
           data-author="沐雨云楼" >
            <span class="post-title" title="nginx为何这么快?">nginx为何这么快?</span>
            <span class="post-date" title="2020-06-20 17:55:10">2020/06/20</span>
        </a>
        
        <a  class="架构 "
           href="/blog/2020/06/20/fw-mq-message-missing/"
           data-tag="mq"
           data-author="沐雨云楼" >
            <span class="post-title" title="MQ如何保证消息不丢失?">MQ如何保证消息不丢失?</span>
            <span class="post-date" title="2020-06-20 17:03:18">2020/06/20</span>
        </a>
        
        <a  class="java "
           href="/blog/2020/06/20/java-base-serializable/"
           data-tag="序列化"
           data-author="沐雨云楼" >
            <span class="post-title" title="java序列化">java序列化</span>
            <span class="post-date" title="2020-06-20 16:29:04">2020/06/20</span>
        </a>
        
        <a  class="架构 "
           href="/blog/2020/06/20/fw-distributed-lock-redis-zk/"
           data-tag="lock,redis,zookeeper"
           data-author="沐雨云楼" >
            <span class="post-title" title="分布式锁用redis还是zk?">分布式锁用redis还是zk?</span>
            <span class="post-date" title="2020-06-20 12:09:55">2020/06/20</span>
        </a>
        
        <a  class="java tools "
           href="/blog/2020/06/19/java-tool-jackson/"
           data-tag="jackson"
           data-author="沐雨云楼" >
            <span class="post-title" title="工具类--jackson">工具类--jackson</span>
            <span class="post-date" title="2020-06-19 13:00:45">2020/06/19</span>
        </a>
        
        <a  class="java tools "
           href="/blog/2020/06/19/java-tool-bean-map/"
           data-tag="beanmap"
           data-author="沐雨云楼" >
            <span class="post-title" title="工具类--bean和map互转">工具类--bean和map互转</span>
            <span class="post-date" title="2020-06-19 12:30:14">2020/06/19</span>
        </a>
        
        <a  class="java test "
           href="/blog/2020/06/18/java-rest-assured-in-action/"
           data-tag="rest"
           data-author="沐雨云楼" >
            <span class="post-title" title="rest-assured实战">rest-assured实战</span>
            <span class="post-date" title="2020-06-18 17:51:56">2020/06/18</span>
        </a>
        
        <a  class="java test "
           href="/blog/2020/06/17/java_rest_assured_wiki_info/"
           data-tag="rest"
           data-author="沐雨云楼" >
            <span class="post-title" title="rest-assured wiki翻译">rest-assured wiki翻译</span>
            <span class="post-date" title="2020-06-17 20:39:11">2020/06/17</span>
        </a>
        
        <a  class="python tornado "
           href="/blog/2020/06/16/tornado-wtforms/"
           data-tag="wtforms"
           data-author="沐雨云楼" >
            <span class="post-title" title="wtforms表单验证">wtforms表单验证</span>
            <span class="post-date" title="2020-06-16 21:52:33">2020/06/16</span>
        </a>
        
        <a  class="python tornado "
           href="/blog/2020/06/16/tornado-sync-to-async/"
           data-tag="aysnc"
           data-author="沐雨云楼" >
            <span class="post-title" title="tornado同步转异步">tornado同步转异步</span>
            <span class="post-date" title="2020-06-16 21:50:25">2020/06/16</span>
        </a>
        
        <a  class="python tornado "
           href="/blog/2020/06/08/python_tornado_info/"
           data-tag="tornado"
           data-author="沐雨云楼" >
            <span class="post-title" title="👍Tornado入门这一篇足以">👍Tornado入门这一篇足以</span>
            <span class="post-date" title="2020-06-08 20:31:32">2020/06/08</span>
        </a>
        
        <a  class="工具 maven "
           href="/blog/2020/06/07/tool-maven/"
           data-tag="tools,工具"
           data-author="沐雨云楼" >
            <span class="post-title" title="maven常用命令和配置">maven常用命令和配置</span>
            <span class="post-date" title="2020-06-07 16:30:11">2020/06/07</span>
        </a>
        
        <a  class="微服务 springboot "
           href="/blog/2020/06/07/spring-initialzr/"
           data-tag="tools,工具"
           data-author="沐雨云楼" >
            <span class="post-title" title="spring initialzr环境编译发布">spring initialzr环境编译发布</span>
            <span class="post-date" title="2020-06-07 15:06:00">2020/06/07</span>
        </a>
        
        <a  class="windows "
           href="/blog/2020/06/07/windows-cmd/"
           data-tag="tools,工具,命令"
           data-author="沐雨云楼" >
            <span class="post-title" title="windows常用命令和技巧">windows常用命令和技巧</span>
            <span class="post-date" title="2020-06-07 11:39:01">2020/06/07</span>
        </a>
        
        <a  class="工具 github "
           href="/blog/2020/06/07/tool-connect-github/"
           data-tag="github"
           data-author="沐雨云楼" >
            <span class="post-title" title="github无法访问解决办法">github无法访问解决办法</span>
            <span class="post-date" title="2020-06-07 10:08:38">2020/06/07</span>
        </a>
        
        <a  class="微服务 spring "
           href="/blog/2020/06/03/spring-transaction/"
           data-tag="transactional"
           data-author="沐雨云楼" >
            <span class="post-title" title="Transactional注解">Transactional注解</span>
            <span class="post-date" title="2020-06-03 22:09:42">2020/06/03</span>
        </a>
        
        <a  class="java dao "
           href="/blog/2020/06/03/java-jpa-query-multi-param/"
           data-tag="JPA"
           data-author="沐雨云楼" >
            <span class="post-title" title="JPA多条件查询">JPA多条件查询</span>
            <span class="post-date" title="2020-06-03 21:38:04">2020/06/03</span>
        </a>
        
        <a  class="java tools "
           href="/blog/2020/06/02/java-tool-fastjson-bug/"
           data-tag="fastjson"
           data-author="沐雨云楼" >
            <span class="post-title" title="Fastjson远程代码高危漏洞">Fastjson远程代码高危漏洞</span>
            <span class="post-date" title="2020-06-02 22:38:28">2020/06/02</span>
        </a>
        
        <a  class="linux docker "
           href="/blog/2020/06/02/docker-introduction/"
           data-tag="docker"
           data-author="沐雨云楼" >
            <span class="post-title" title="👍docker入门看这一篇就够了">👍docker入门看这一篇就够了</span>
            <span class="post-date" title="2020-06-02 22:22:30">2020/06/02</span>
        </a>
        
        <a  class="面试 "
           href="/blog/2020/06/02/interview-java-question/"
           data-tag="面试"
           data-author="沐雨云楼" >
            <span class="post-title" title="java常见面试题">java常见面试题</span>
            <span class="post-date" title="2020-06-02 22:15:48">2020/06/02</span>
        </a>
        
        <a  class="微服务 "
           href="/blog/2020/06/02/microservice-why/"
           data-tag="微服务"
           data-author="沐雨云楼" >
            <span class="post-title" title="牛逼公司一定要使用微服务？">牛逼公司一定要使用微服务？</span>
            <span class="post-date" title="2020-06-02 21:15:29">2020/06/02</span>
        </a>
        
        <a  class="面试 "
           href="/blog/2020/06/02/interview-company/"
           data-tag="面试"
           data-author="沐雨云楼" >
            <span class="post-title" title="IT互联网公司名单">IT互联网公司名单</span>
            <span class="post-date" title="2020-06-02 20:41:23">2020/06/02</span>
        </a>
        
        <a  class="java 并发 "
           href="/blog/2020/06/02/java-concurrent-aqs/"
           data-tag="java,并发"
           data-author="沐雨云楼" >
            <span class="post-title" title="java并发AQS">java并发AQS</span>
            <span class="post-date" title="2020-06-02 20:01:48">2020/06/02</span>
        </a>
        
        <a  class="ai "
           href="/blog/2020/05/30/ai-learn-catalog/"
           data-tag="ai"
           data-author="沐雨云楼" >
            <span class="post-title" title="AI学习目录">AI学习目录</span>
            <span class="post-date" title="2020-05-30 08:49:39">2020/05/30</span>
        </a>
        
        <a  class="工具 hexo "
           href="/blog/2020/05/29/hexo-theme-math/"
           data-tag="工具,hexo"
           data-author="沐雨云楼" >
            <span class="post-title" title="hexo主题支持MathJax">hexo主题支持MathJax</span>
            <span class="post-date" title="2020-05-29 09:36:46">2020/05/29</span>
        </a>
        
        <a  class="db redis "
           href="/blog/2020/05/28/redis-memory-eliminate/"
           data-tag="redis"
           data-author="沐雨云楼" >
            <span class="post-title" title="Redis的内存淘汰策略">Redis的内存淘汰策略</span>
            <span class="post-date" title="2020-05-28 21:37:04">2020/05/28</span>
        </a>
        
        <a  class="工具 markdowm "
           href="/blog/2020/05/28/markdown-math-express/"
           data-tag="工具,markdowm"
           data-author="沐雨云楼" >
            <span class="post-title" title="markdown数学公式">markdown数学公式</span>
            <span class="post-date" title="2020-05-28 08:02:03">2020/05/28</span>
        </a>
        
        <a  class="python "
           href="/blog/2020/05/21/python_install/"
           data-tag="python"
           data-author="沐雨云楼" >
            <span class="post-title" title="python环境安装">python环境安装</span>
            <span class="post-date" title="2020-05-21 21:37:04">2020/05/21</span>
        </a>
        
        <a  class="python "
           href="/blog/2020/05/21/python_base/"
           data-tag="python"
           data-author="沐雨云楼" >
            <span class="post-title" title="python基本语法">python基本语法</span>
            <span class="post-date" title="2020-05-21 00:00:00">2020/05/21</span>
        </a>
        
        <a  class="其他 "
           href="/blog/2020/05/20/todo-list/"
           data-tag="plan,计划"
           data-author="沐雨云楼" >
            <span class="post-title" title="计划">计划</span>
            <span class="post-date" title="2020-05-20 11:04:19">2020/05/20</span>
        </a>
        
        <a  class="工具 "
           href="/blog/2020/05/20/blog-template/"
           data-tag="模板"
           data-author="沐雨云楼" >
            <span class="post-title" title="博客自定义模板">博客自定义模板</span>
            <span class="post-date" title="2020-05-20 05:20:00">2020/05/20</span>
        </a>
        
    </nav>
</div>

    </div>
    <div class="hide-list">
        <div class="semicircle" data-title="切换全屏 快捷键 s">
            <div class="brackets first"><</div>
            <div class="brackets">&gt;</div>
        </div>
    </div>
</aside>
<div class="post">
    <div class="pjax">
        <article id="post-python-tool-buildin-func" class="article article-type-post" itemscope itemprop="blogPost">
    
        <h1 class="article-title">👍python内置函数</h1>
    
    <div class="article-meta">
        
        
        <span class="author"><a>沐雨云楼</a></span>
        
        
        <span class="book">
            
                <a  data-rel="python">python</a>
            
        </span>
        
        
        <span class="tag">
            
            <a class="color5">func</a>
            
        </span>
        
    </div>
    <div class="article-meta">
        
            发布时间 : <time class="date" title='最后更新: 2020-09-12 21:21:47'>2020-06-24 18:31</time>
        
    </div>
    <div class="article-meta">
        
        <span>字数:8.4k</span>
        
        
        <span id="busuanzi_container_page_pv">
            阅读 :<span id="busuanzi_value_page_pv">
                <span class="count-comment">
                    <span class="spinner">
                      <div class="cube1"></div>
                      <div class="cube2"></div>
                    </span>
                </span>
            </span>
        </span>
        
        
        <span class="top-comment" title="跳转至评论区">
            <a href="#comments">
                评论:<span class="count-comment">
                    <span class="spinner">
                      <div class="cube1"></div>
                      <div class="cube2"></div>
                    </span>
                </span>
            </a>
        </span>
        
    </div>
    
    <div class="toc-ref">
    
        <ol class="toc"><li class="toc-item toc-level-2"><a class="toc-link" href="#1-函数表格"><span class="toc-text">1.函数表格</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#2-数学运算类"><span class="toc-text">2.数学运算类</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#2-1-abs"><span class="toc-text">2-1.abs</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#2-2-complex"><span class="toc-text">2-2.complex</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#2-3-divmod"><span class="toc-text">2-3.divmod</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#2-4-类型转化"><span class="toc-text">2-4.类型转化</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#2-5-pow"><span class="toc-text">2-5.pow</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#2-6-round"><span class="toc-text">2-6.round</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#2-7-sum"><span class="toc-text">2-7.sum</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#2-8-range"><span class="toc-text">2-8.range</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#3-集合类操作"><span class="toc-text">3.集合类操作</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#3-1-format"><span class="toc-text">3-1.format</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#3-2-转化"><span class="toc-text">3-2.转化</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#3-3-最值"><span class="toc-text">3-3.最值</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#3-4-enumerate"><span class="toc-text">3-4.enumerate</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#3-5-reversed"><span class="toc-text">3-5.reversed</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#4-逻辑判断"><span class="toc-text">4.逻辑判断</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#4-1-all"><span class="toc-text">4-1.all</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#4-2-any"><span class="toc-text">4-2.any</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#5-反射"><span class="toc-text">5.反射</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#5-1-callable"><span class="toc-text">5-1.callable</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#5-2-classmethod"><span class="toc-text">5-2.classmethod</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#5-3-compile"><span class="toc-text">5-3.compile</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#5-4-dir"><span class="toc-text">5-4.dir</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#5-5-delattr"><span class="toc-text">5-5.delattr</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#5-6-eval"><span class="toc-text">5-6.eval</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#5-7-exec"><span class="toc-text">5-7.exec</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#5-8-filter"><span class="toc-text">5-8.filter</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#5-9-getattr"><span class="toc-text">5-9.getattr</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#5-10-globals"><span class="toc-text">5-10.globals</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#5-11-hasattr"><span class="toc-text">5-11.hasattr</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#5-12-hash"><span class="toc-text">5-12.hash</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#5-13-id"><span class="toc-text">5-13.id</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#5-14-isinstance"><span class="toc-text">5-14.isinstance</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#5-15-issubclass"><span class="toc-text">5-15.issubclass</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#5-16-len"><span class="toc-text">5-16.len</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#5-17-locals"><span class="toc-text">5-17.locals</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#5-18-map"><span class="toc-text">5-18.map</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#5-19-bytearray"><span class="toc-text">5-19.bytearray</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#5-20-memoryview"><span class="toc-text">5-20.memoryview</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#5-21-next"><span class="toc-text">5-21.next</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#5-22-property"><span class="toc-text">5-22.property</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#5-23-vars"><span class="toc-text">5-23.vars</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#5-24-setattr"><span class="toc-text">5-24.setattr</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#5-25-slice"><span class="toc-text">5-25.slice</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#5-26-staticmethod"><span class="toc-text">5-26.staticmethod</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#5-27-type"><span class="toc-text">5-27.type</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#5-28-repr"><span class="toc-text">5-28.repr</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#5-29-zip"><span class="toc-text">5-29.zip</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#5-30-xrange"><span class="toc-text">5-30.xrange</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#6-IO操作"><span class="toc-text">6.IO操作</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#6-1-input"><span class="toc-text">6-1.input</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#6-2-open"><span class="toc-text">6-2.open</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#6-3-print"><span class="toc-text">6-3.print</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#7-其他"><span class="toc-text">7.其他</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#7-1-help"><span class="toc-text">7-1.help</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#7-2-import"><span class="toc-text">7-2.import</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#8-总结"><span class="toc-text">8.总结</span></a></li></ol>
    
<style>
    .left-col .switch-btn,
    .left-col .switch-area {
        display: none;
    }
    .toc-level-4 i,
    .toc-level-4 ol {
        display: none !important;
    }
</style>
</div>
    
    <div class="article-entry" itemprop="articleBody">
      
        <p>本编研究下python的内置函数(属性/魔法方法<a href="https://iworkh.gitee.io/blog/2020/06/25/python-tool-buildin-attr/">下一篇</a>研究)</p>
<blockquote>
<p>基于python3的版本来研究，内容虽有点比较多，只要耐心看完必定有所收获。</p>
</blockquote>
<p><a href="https://gitee.com/iworkh/iworkh-dev-python/tree/develop/code/python_test/test02" target="_blank" rel="noopener">源码坐标</a></p>
<h2 id="1-函数表格"><a href="#1-函数表格" class="headerlink" title="1.函数表格"></a>1.函数表格</h2><p>这先盗用下菜鸟教程里的内置函数表格，后面会对每个详细介绍，并进行补充</p>
<ul>
<li><a href="https://docs.python.org/zh-cn/3/library/functions.html" target="_blank" rel="noopener">python3官网-内置函数doc</a></li>
</ul>
<table>
<thead>
<tr>
<th align="left"></th>
<th align="left"></th>
<th align="left">内置函数</th>
<th align="left"></th>
<th align="left"></th>
</tr>
</thead>
<tbody><tr>
<td align="left"><a href="https://www.runoob.com/python/func-number-abs.html" target="_blank" rel="noopener">abs()</a></td>
<td align="left"><a href="https://www.runoob.com/python/python-func-divmod.html" target="_blank" rel="noopener">divmod()</a></td>
<td align="left"><a href="https://www.runoob.com/python/python-func-input.html" target="_blank" rel="noopener">input()</a></td>
<td align="left"><a href="https://www.runoob.com/python/python-func-open.html" target="_blank" rel="noopener">open()</a></td>
<td align="left"><a href="https://www.runoob.com/python/python-func-staticmethod.html" target="_blank" rel="noopener">staticmethod()</a></td>
</tr>
<tr>
<td align="left"><a href="https://www.runoob.com/python/python-func-all.html" target="_blank" rel="noopener">all()</a></td>
<td align="left"><a href="https://www.runoob.com/python/python-func-enumerate.html" target="_blank" rel="noopener">enumerate()</a></td>
<td align="left"><a href="https://www.runoob.com/python/python-func-int.html" target="_blank" rel="noopener">int()</a></td>
<td align="left"><a href="https://www.runoob.com/python/python-func-ord.html" target="_blank" rel="noopener">ord()</a></td>
<td align="left"><a href="https://www.runoob.com/python/python-func-str.html" target="_blank" rel="noopener">str()</a></td>
</tr>
<tr>
<td align="left"><a href="https://www.runoob.com/python/python-func-any.html" target="_blank" rel="noopener">any()</a></td>
<td align="left"><a href="https://www.runoob.com/python/python-func-eval.html" target="_blank" rel="noopener">eval()</a></td>
<td align="left"><a href="https://www.runoob.com/python/python-func-isinstance.html" target="_blank" rel="noopener">isinstance()</a></td>
<td align="left"><a href="https://www.runoob.com/python/func-number-pow.html" target="_blank" rel="noopener">pow()</a></td>
<td align="left"><a href="https://www.runoob.com/python/python-func-sum.html" target="_blank" rel="noopener">sum()</a></td>
</tr>
<tr>
<td align="left"><a href="https://www.runoob.com/python/python-func-basestring.html" target="_blank" rel="noopener">basestring()</a></td>
<td align="left"><a href="https://www.runoob.com/python/python-func-execfile.html" target="_blank" rel="noopener">execfile()</a></td>
<td align="left"><a href="https://www.runoob.com/python/python-func-issubclass.html" target="_blank" rel="noopener">issubclass()</a></td>
<td align="left"><a href="https://www.runoob.com/python/python-func-print.html" target="_blank" rel="noopener">print()</a></td>
<td align="left"><a href="https://www.runoob.com/python/python-func-super.html" target="_blank" rel="noopener">super()</a></td>
</tr>
<tr>
<td align="left"><a href="https://www.runoob.com/python/python-func-bin.html" target="_blank" rel="noopener">bin()</a></td>
<td align="left"><a href="https://www.runoob.com/python/python-func-file.html" target="_blank" rel="noopener">file()</a></td>
<td align="left"><a href="https://www.runoob.com/python/python-func-iter.html" target="_blank" rel="noopener">iter()</a></td>
<td align="left"><a href="https://www.runoob.com/python/python-func-property.html" target="_blank" rel="noopener">property()</a></td>
<td align="left"><a href="https://www.runoob.com/python/att-tuple-tuple.html" target="_blank" rel="noopener">tuple()</a></td>
</tr>
<tr>
<td align="left"><a href="https://www.runoob.com/python/python-func-bool.html" target="_blank" rel="noopener">bool()</a></td>
<td align="left"><a href="https://www.runoob.com/python/python-func-filter.html" target="_blank" rel="noopener">filter()</a></td>
<td align="left"><a href="https://www.runoob.com/python/att-string-len.html" target="_blank" rel="noopener">len()</a></td>
<td align="left"><a href="https://www.runoob.com/python/python-func-range.html" target="_blank" rel="noopener">range()</a></td>
<td align="left"><a href="https://www.runoob.com/python/python-func-type.html" target="_blank" rel="noopener">type()</a></td>
</tr>
<tr>
<td align="left"><a href="https://www.runoob.com/python/python-func-bytearray.html" target="_blank" rel="noopener">bytearray()</a></td>
<td align="left"><a href="https://www.runoob.com/python/python-func-float.html" target="_blank" rel="noopener">float()</a></td>
<td align="left"><a href="https://www.runoob.com/python/att-list-list.html" target="_blank" rel="noopener">list()</a></td>
<td align="left"><a href="https://www.runoob.com/python/python-func-raw_input.html" target="_blank" rel="noopener">raw_input()</a></td>
<td align="left"><a href="https://www.runoob.com/python/python-func-unichr.html" target="_blank" rel="noopener">unichr()</a></td>
</tr>
<tr>
<td align="left"><a href="https://www.runoob.com/python/python-func-callable.html" target="_blank" rel="noopener">callable()</a></td>
<td align="left"><a href="https://www.runoob.com/python/att-string-format.html" target="_blank" rel="noopener">format()</a></td>
<td align="left"><a href="https://www.runoob.com/python/python-func-locals.html" target="_blank" rel="noopener">locals()</a></td>
<td align="left"><a href="https://www.runoob.com/python/python-func-reduce.html" target="_blank" rel="noopener">reduce()</a></td>
<td align="left">unicode()</td>
</tr>
<tr>
<td align="left"><a href="https://www.runoob.com/python/python-func-chr.html" target="_blank" rel="noopener">chr()</a></td>
<td align="left"><a href="https://www.runoob.com/python/python-func-frozenset.html" target="_blank" rel="noopener">frozenset()</a></td>
<td align="left"><a href="https://www.runoob.com/python/python-func-long.html" target="_blank" rel="noopener">long()</a></td>
<td align="left"><a href="https://www.runoob.com/python/python-func-reload.html" target="_blank" rel="noopener">reload()</a></td>
<td align="left"><a href="https://www.runoob.com/python/python-func-vars.html" target="_blank" rel="noopener">vars()</a></td>
</tr>
<tr>
<td align="left"><a href="https://www.runoob.com/python/python-func-classmethod.html" target="_blank" rel="noopener">classmethod()</a></td>
<td align="left"><a href="https://www.runoob.com/python/python-func-getattr.html" target="_blank" rel="noopener">getattr()</a></td>
<td align="left"><a href="https://www.runoob.com/python/python-func-map.html" target="_blank" rel="noopener">map()</a></td>
<td align="left"><a href="https://www.runoob.com/python/python-func-repr.html" target="_blank" rel="noopener">repr()</a></td>
<td align="left"><a href="https://www.runoob.com/python/python-func-xrange.html" target="_blank" rel="noopener">xrange()</a></td>
</tr>
<tr>
<td align="left"><a href="https://www.runoob.com/python/func-number-cmp.html" target="_blank" rel="noopener">cmp()</a></td>
<td align="left"><a href="https://www.runoob.com/python/python-func-globals.html" target="_blank" rel="noopener">globals()</a></td>
<td align="left"><a href="https://www.runoob.com/python/func-number-max.html" target="_blank" rel="noopener">max()</a></td>
<td align="left"><a href="https://www.runoob.com/python/att-list-reverse.html" target="_blank" rel="noopener">reverse()</a></td>
<td align="left"><a href="https://www.runoob.com/python/python-func-zip.html" target="_blank" rel="noopener">zip()</a></td>
</tr>
<tr>
<td align="left"><a href="https://www.runoob.com/python/python-func-compile.html" target="_blank" rel="noopener">compile()</a></td>
<td align="left"><a href="https://www.runoob.com/python/python-func-hasattr.html" target="_blank" rel="noopener">hasattr()</a></td>
<td align="left"><a href="https://www.runoob.com/python/python-func-memoryview.html" target="_blank" rel="noopener">memoryview()</a></td>
<td align="left"><a href="https://www.runoob.com/python/func-number-round.html" target="_blank" rel="noopener">round()</a></td>
<td align="left"><a href="https://www.runoob.com/python/python-func-__import__.html" target="_blank" rel="noopener"><strong>import</strong>()</a></td>
</tr>
<tr>
<td align="left"><a href="https://www.runoob.com/python/python-func-complex.html" target="_blank" rel="noopener">complex()</a></td>
<td align="left"><a href="https://www.runoob.com/python/python-func-hash.html" target="_blank" rel="noopener">hash()</a></td>
<td align="left"><a href="https://www.runoob.com/python/func-number-min.html" target="_blank" rel="noopener">min()</a></td>
<td align="left"><a href="https://www.runoob.com/python/python-func-set.html" target="_blank" rel="noopener">set()</a></td>
<td align="left"></td>
</tr>
<tr>
<td align="left"><a href="https://www.runoob.com/python/python-func-delattr.html" target="_blank" rel="noopener">delattr()</a></td>
<td align="left"><a href="https://www.runoob.com/python/python-func-help.html" target="_blank" rel="noopener">help()</a></td>
<td align="left"><a href="https://www.runoob.com/python/python-func-next.html" target="_blank" rel="noopener">next()</a></td>
<td align="left"><a href="https://www.runoob.com/python/python-func-setattr.html" target="_blank" rel="noopener">setattr()</a></td>
<td align="left"></td>
</tr>
<tr>
<td align="left"><a href="https://www.runoob.com/python/python-func-dict.html" target="_blank" rel="noopener">dict()</a></td>
<td align="left"><a href="https://www.runoob.com/python/python-func-hex.html" target="_blank" rel="noopener">hex()</a></td>
<td align="left">object()</td>
<td align="left"><a href="https://www.runoob.com/python/python-func-slice.html" target="_blank" rel="noopener">slice()</a></td>
<td align="left"></td>
</tr>
<tr>
<td align="left"><a href="https://www.runoob.com/python/python-func-dir.html" target="_blank" rel="noopener">dir()</a></td>
<td align="left"><a href="https://www.runoob.com/python/python-func-id.html" target="_blank" rel="noopener">id()</a></td>
<td align="left"><a href="https://www.runoob.com/python/python-func-oct.html" target="_blank" rel="noopener">oct()</a></td>
<td align="left"><a href="https://www.runoob.com/python/python-func-sorted.html" target="_blank" rel="noopener">sorted()</a></td>
<td align="left"><a href="https://www.runoob.com/python/python-func-exec.html" target="_blank" rel="noopener">exec 内置表达式</a></td>
</tr>
</tbody></table>
<blockquote>
<p>下面分类来研究下每个函数</p>
</blockquote>
<h2 id="2-数学运算类"><a href="#2-数学运算类" class="headerlink" title="2.数学运算类"></a>2.数学运算类</h2><h3 id="2-1-abs"><a href="#2-1-abs" class="headerlink" title="2-1.abs"></a>2-1.abs</h3><p><code>abs(x)</code>函数返回数字的绝对值。</p>
<blockquote>
<p>x: 数值表达式，可以是整数，浮点数，复数。</p>
<ul>
<li>参数可以是整型，也可以是复数</li>
<li>若参数是复数，则返回复数的模</li>
</ul>
</blockquote>
<p><strong>演示</strong></p>
<pre><code class="python">class MyTestCase(unittest.TestCase):
    def test_abs(self):
        a = 3.14
        b = -7.36
        c = complex(3, 4)  # 创建一个复数
        print(abs(a))  # 3.14
        print(abs(b))  # 7.36
        print(abs(c))  # 5.0</code></pre>
<h3 id="2-2-complex"><a href="#2-2-complex" class="headerlink" title="2-2.complex"></a>2-2.complex</h3><p><code>complex()</code>函数用于创建一个值为<code>real + imag * j</code>的复数或者转化一个字符串或数为复数。如果第一个参数为字符串，则不需要指定第二个参数。。</p>
<ul>
<li>real: int, long, float或字符串；</li>
<li>imag: int, long, float；</li>
</ul>
<p><strong>演示</strong></p>
<pre><code class="python">class MyTestCase(unittest.TestCase):
    def test_complex(self):
        a = complex(3, 4)
        b = complex(1)
        c = complex(&#39;3&#39;)
        d = complex(&quot;3+4j&quot;)
        print(a) # (3+4j)
        print(b) # (1+0j)
        print(c) # (3+0j)
        print(d) # (3+4j)</code></pre>
<h3 id="2-3-divmod"><a href="#2-3-divmod" class="headerlink" title="2-3.divmod"></a>2-3.divmod</h3><p><code>divmod(a, b)</code>函数接收两个数字类型（非复数）参数，返回一个包含商和余数的元组(a // b, a % b)。</p>
<ul>
<li>a: 数字，非复数。</li>
<li>b: 数字，非复数。</li>
</ul>
<img src="/blog/images/python/base/buildin_divmod.png" width="650px">


<p><strong>演示</strong></p>
<pre><code class="python">class MyTestCase(unittest.TestCase):
    def test_divmod(self):
        print(divmod(3, 2))  # (1, 1)
        print(divmod(3, -2))  # (-2, -1),
        print(divmod(-3, 2))  # (-2, 1)
        print(divmod(-3, -2))  # (1, -1)
        print(divmod(3, 1.2))  # (2.0, 0.6000000000000001)</code></pre>
<blockquote>
<p>以<code>divmod(3, -2)</code>来分析下：</p>
<ul>
<li><code>b=-2</code>是负数，y符号要跟b保持一致，所以y也得是负数。a、b都取正数，<code>3/2</code>的余数为1，所以<code>y=-1</code></li>
<li>以<code>a=3</code>为目标,现在<code>y=-1</code>了，所以我们计算出<code>b*x=4</code>才能和<code>y=-1</code>相加为3，现在b=-2，要使得<code>b*x=4</code>,那么x得为<code>-2</code></li>
</ul>
</blockquote>
<h3 id="2-4-类型转化"><a href="#2-4-类型转化" class="headerlink" title="2-4.类型转化"></a>2-4.类型转化</h3><p>int、float、long、char、bool、二进制、八进制、十六进制等转化</p>
<ul>
<li><code>float()</code>函数用于将整数和字符串转换成浮点数。</li>
<li><code>int()</code> 函数用于将一个字符串或数字转换为整型。<blockquote>
<p><code>int(x, base=10)</code>:x为字符串或数字；base为进制数，默认十进制。</p>
</blockquote>
</li>
<li><code>chr()</code> 用一个整数作参数，返回一个对应的字符。<blockquote>
<p><code>chr(i)</code>: i 可以是 10 进制也可以是 16 进制的形式的数字，数字范围为 0 到 1,114,111 (16 进制为0x10FFFF)。</p>
</blockquote>
</li>
<li><code>bin()</code> 返回一个整数 int 或者长整数 long int 的二进制表示。<blockquote>
<p><code>bin(x)</code>: x为int 或者 long int 数字</p>
</blockquote>
</li>
<li><code>oct()</code> 函数将一个整数转换成8进制字符串。<blockquote>
<p><code>oct(x)</code>: x为整数。</p>
</blockquote>
</li>
<li><code>hex()</code> 函数用于将一个指定数字转换为 16 进制数。<blockquote>
<p><code>hex(x)</code>: x为整数</p>
</blockquote>
</li>
<li><code>bool()</code> 函数用于将整数和字符串转换成浮点数。<blockquote>
<p><code>bool(x)</code>: x为要进行转换的参数。不写参数默认是False</p>
</blockquote>
</li>
</ul>
<p>更多的ascii码可以查a<a href="http://www.96yx.com/tool/ASC2.htm" target="_blank" rel="noopener">ascii码表</a></p>
<p><strong>演示</strong></p>
<pre><code class="python">class MyTestCase(unittest.TestCase):
    def test_float(self):
        print(float(1))  # 1.0
        print(float(-123.6))  # -123.6
        print(float(&#39;123&#39;))  # 123.0

    def test_int(self):
        print(int())  # 默认0
        print(int(2))  # 2
        print(int(2.5))  # 2
        print(int(&#39;1&#39;,2))  # 1
        print(int(&#39;10&#39;,8))  # 8
        print(int(&#39;10&#39;,10))  # 10
        print(int(&#39;10&#39;,16))  # 16
        print(int(&#39;0x10&#39;,16))  # 16

    def test_chr(self):
        print(chr(0x30)) # 0
        print(chr(97)) # a

    def test_bin(self):
        print(bin(97)) # 0b1100001 
        print(bin(88)) # 0b1011000

    def test_oct(self):
        print(oct(97)) # 0o141
        print(oct(88)) # 0o130

    def test_hex(self):
        print(hex(97)) # 0x61
        print(hex(88)) # 0x58 

    def test_bool(self):
        print(bool()) # False
        print(bool(True)) # True
        print(bool(0)) # False
        print(bool(88)) # True
        print(issubclass(bool, int)) # True: bool 是 int 子类</code></pre>
<h3 id="2-5-pow"><a href="#2-5-pow" class="headerlink" title="2-5.pow"></a>2-5.pow</h3><p><code>pow()</code>方法返回 x^y（x的y次方）的值。</p>
<p><code>pow(x, y[, z])</code></p>
<blockquote>
<p>函数是计算x的y次方，如果z在存在，则再对结果进行取模，其结果等效于<code>pow(x,y) %z</code></p>
</blockquote>
<p>math 模块 pow() 方法的语法:</p>
<pre><code class="python">import math

math.pow( x, y )</code></pre>
<p>pow() 通过内置的方法直接调用，内置方法会把参数作为<strong>整型</strong>，而 math 模块则会把参数转换为 <strong>float</strong>。</p>
<p><strong>演示</strong></p>
<pre><code class="python">class MyTestCase(unittest.TestCase):
    def test_divmod(self):
        print(pow(3, 0))  # 1 原生
        print(pow(3, 2))  # 9 原生
        print(math.pow(3, 2))  # 9.0 math的</code></pre>
<h3 id="2-6-round"><a href="#2-6-round" class="headerlink" title="2-6.round"></a>2-6.round</h3><p><code>round()</code> 方法返回浮点数 x 的四舍五入值，准确的说保留值将保留到离上一位更近的一端（四舍五入）。</p>
<blockquote>
<p>精度要求高的，不建议使用该函数。</p>
</blockquote>
<p><strong>演示</strong></p>
<pre><code class="python">class MyTestCase(unittest.TestCase):
    def test_round(self):
        print(round(3))  # 3
        print(round(70.43456))  # 70
        print(round(70.50456))  #  71
        print(round(70.23456, 3))  # 70.235
        print(round(-100.000056, 3))  # -100.0</code></pre>
<h3 id="2-7-sum"><a href="#2-7-sum" class="headerlink" title="2-7.sum"></a>2-7.sum</h3><p><code>sum()</code>方法对系列进行求和计算。</p>
<p><code>sum(iterable[, start])</code></p>
<ul>
<li>iterable: 可迭代对象，如：列表、元组、集合。</li>
<li>start – 指定相加的参数，如果没有设置这个值，默认为0。</li>
</ul>
<p><strong>演示</strong></p>
<pre><code class="python">class MyTestCase(unittest.TestCase):
    def test_sum(self):
        print(sum([1,2,3,4]))  # 10 列表
        print(sum((1,2,3,4)))  # 10 元组
        print(sum((1,2,3,4),10))  # 20</code></pre>
<h3 id="2-8-range"><a href="#2-8-range" class="headerlink" title="2-8.range"></a>2-8.range</h3><p><code>range()</code>函数返回的是一个可迭代对象（类型是对象），而不是列表类型， 所以打印的时候不会打印列表。<br><code>list()</code> 函数是对象迭代器，可以把range()返回的可迭代对象转为一个列表，返回的变量类型为列表。</p>
<p><code>range(start, stop[, step])</code></p>
<ul>
<li>start: 计数从 start 开始。默认是从 0 开始。例如range（5）等价于range（0， 5）;</li>
<li>stop: 计数到 stop 结束，但不包括 stop。例如：range（0， 5） 是[0, 1, 2, 3, 4]没有5</li>
<li>step：步长，默认为1。例如：range（0， 5） 等价于 range(0, 5, 1)</li>
</ul>
<div class="admonition attention">
<p class="fa admonition-title">注意</p>
<p>
    range：左包括，右不包括(从start开始，stop前一个结束)
</p>
</div>

<p><strong>演示</strong></p>
<pre><code class="python">class MyTestCase(unittest.TestCase):
    def test_range(self):
        print(list(range(10)))  # [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
        print(list(range(1, 10)))  # [1, 2, 3, 4, 5, 6, 7, 8, 9]
        print(list(range(1, 10, 2)))  # [1, 3, 5, 7, 9]
        print(list(range(10, 0, -1)))  # [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]
</code></pre>
<h2 id="3-集合类操作"><a href="#3-集合类操作" class="headerlink" title="3.集合类操作"></a>3.集合类操作</h2><h3 id="3-1-format"><a href="#3-1-format" class="headerlink" title="3-1.format"></a>3-1.format</h3><p>Python2.6 开始，新增了一种格式化字符串的函数 str.format()，它增强了字符串格式化的功能。</p>
<p>基本语法是通过<code>{}</code>和<code>:</code>来代替以前的<code>%</code> 。</p>
<p><strong>演示</strong></p>
<pre><code class="python">class MyTestCase(unittest.TestCase):
    def test_formart(self):
        print(&quot;{} - {}&quot;.format(&#39;iworkh&#39;, &#39;沐雨云楼&#39;))  # iworkh - 沐雨云楼
        print(&quot;{1} - {0}&quot;.format(&#39;iworkh&#39;, &#39;沐雨云楼&#39;))  # 沐雨云楼 - iworkh
        print(&quot;{company} - {name}&quot;.format(company=&#39;iworkh&#39;, name=&#39;沐雨云楼&#39;))  # iworkh - 沐雨云楼
        # 字典
        data_dic = {&#39;company&#39;: &#39;iworkh&#39;, &#39;name&#39;: &#39;沐雨云楼&#39;}
        print(&quot;网站：{company} - 名称：{name}&quot;.format(**data_dic))  # 网站：iworkh - 名称：沐雨云楼
        # 列表: 说明 0[1]中的0代表是data_list，1表示list里第一元素
        data_list1 = [&#39;iworkh&#39;, &#39;沐雨云楼&#39;]
        data_list2 = [&#39;test&#39;, &#39;yuxl&#39;]
        print(&quot;网站：{0[0]} - 名称：{1[1]}&quot;.format(data_list1, data_list2))  # 网站：iworkh - 名称：沐雨云楼
        # 格式化
        print(&quot;{:.2f}&quot;.format(3.1415926))
        # {}的转义
        print(&quot;{{}}是表示转移的,{:.2%}&quot;.format(0.26))
</code></pre>
<p><strong>主要关注几点：</strong></p>
<ul>
<li>一个<code>{}</code>占位符，两个<code>{}</code>可转义<code>{}</code></li>
<li>可用通过数字、参数名来格式化，数据值可用是dict、也可以是list</li>
<li>还可以来格式化数字 <a href="https://www.runoob.com/python/att-string-format.html" target="_blank" rel="noopener">更多数字格式化</a></li>
</ul>
<h3 id="3-2-转化"><a href="#3-2-转化" class="headerlink" title="3-2.转化"></a>3-2.转化</h3><ul>
<li><code>str()</code> 函数将对象转化为适于人阅读的形式。</li>
<li><code>iter()</code>  函数用来生成迭代器。<blockquote>
<p><code>iter(object[, sentinel])</code>:<br>object: 支持迭代的集合对象。<br>sentinel: 如果传递了第二个参数，则参数 object 必须是一个可调用的对象（如，函数），<br>此时，iter 创建了一个迭代器对象，每次调用这个迭代器对象的<strong>next</strong>()方法时，都会调用 object。</p>
</blockquote>
</li>
<li><code>dict()</code> 函数用于创建一个字典。<blockquote>
<p>三种创建方式</p>
<ul>
<li><code>dict(**kwarg)</code>： <code>**kwargs</code>是关键字</li>
<li><code>dict(mapping, **kwarg)</code>：<code>mapping</code>是元素的容器。</li>
<li><code>dict(iterable, **kwarg)</code>：<code>iterable</code>是可迭代对象。</li>
</ul>
</blockquote>
</li>
<li><code>list()</code> 函数用于将元组或字符串转换为列表。<blockquote>
<p>元组与列表是非常类似的，区别在于元组的元素值不能修改，元组是放在括号中，列表是放于方括号中。</p>
</blockquote>
</li>
<li><code>tuple()</code><blockquote>
<p><code>tuple( iterable )</code>: iterable为要转换为元组的可迭代序列。</p>
</blockquote>
</li>
<li><code>set()</code> 函数创建一个无序不重复元素集，可进行关系测试，删除重复数据，还可以计算交集、差集、并集等。<blockquote>
<p><code>set([iterable])</code>: iterable是可迭代对象对象(列表、字典、元组等等)；</p>
</blockquote>
</li>
<li><code>frozenset()</code><blockquote>
<p> <code>frozenset([iterable])</code> : iterable是可迭代对象对象(列表、字典、元组等等)；</p>
</blockquote>
</li>
<li><code>sorted()</code> 函数对所有可迭代的对象进行排序操作。<blockquote>
<p>sort 是应用在 list 上的方法（<strong>在原有的list上操作</strong>）<br>sorted  可以对所有可迭代的对象进行排序操作。(<strong>返回一个新的 list</strong>)<br>sorted(iterable, key=None, reverse=False) </p>
<ul>
<li>iterable: 可迭代对象。</li>
<li>key:主要是用来进行比较的元素，只有一个参数，具体的函数的参数就是取自于可迭代对象中，指定可迭代对象中的一个元素来进行排序。</li>
<li>reverse :  排序规则，reverse = True 降序 ， reverse = False 升序（默认）。</li>
</ul>
</blockquote>
</li>
</ul>
<p><strong>演示</strong></p>
<pre><code class="python">class MyTestCase(unittest.TestCase):
    def test_str(self):
        dict = {&#39;company&#39;: &#39;iworkh&#39;, &#39;name&#39;: &#39;沐雨云楼&#39;}
        print(str(dict))  # {&#39;company&#39;: &#39;iworkh&#39;, &#39;name&#39;: &#39;沐雨云楼&#39;}
        list = [&#39;iworkh&#39;, &#39;沐雨云楼&#39;]
        print(str(list))  # [&#39;iworkh&#39;, &#39;沐雨云楼&#39;]

    def test_iter(self):
        list = [&#39;iworkh&#39;, &#39;沐雨云楼&#39;]
        print(iter(list))  # &lt;list_iterator object at 0x000002D9B9E35D48&gt;
        for item in iter(list):
            print(item)

        dict = {&#39;company&#39;: &#39;iworkh&#39;, &#39;name&#39;: &#39;沐雨云楼&#39;}
        print(iter(dict))  # &lt;dict_keyiterator object at 0x0000020ACFCE07C8&gt;
        for item_key in iter(dict):
            print(&quot;{}-{}&quot;.format(item_key, dict[item_key]))

    def test_dict(self):
        print(dict())  # 空dict {}
        print(dict(name=&#39;沐雨云楼&#39;, age=20, sex=&#39;男&#39;))  # {&#39;name&#39;: &#39;沐雨云楼&#39;, &#39;age&#39;: 20, &#39;sex&#39;: &#39;男&#39;}
        list_zip = zip([&#39;name&#39;, &#39;age&#39;, &#39;sex&#39;], [&#39;沐雨云楼&#39;, 20, &#39;男&#39;])
        print(dict(list_zip))  # {&#39;name&#39;: &#39;沐雨云楼&#39;, &#39;age&#39;: 20, &#39;sex&#39;: &#39;男&#39;}
        tuple_list = [(&#39;name&#39;, &#39;沐雨云楼&#39;), (&#39;age&#39;, 20), (&#39;sex&#39;, &#39;男&#39;)]
        print(dict(tuple_list))  # {&#39;name&#39;: &#39;沐雨云楼&#39;, &#39;age&#39;: 20, &#39;sex&#39;: &#39;男&#39;}

    def test_list(self):
        tuple = (&#39;iworkh&#39;, 20, &#39;男&#39;)
        print(list(tuple))  # [&#39;iworkh&#39;, 20, &#39;男&#39;]
        print(list(&#39;iowrkh 沐雨云楼&#39;))  # [&#39;i&#39;, &#39;o&#39;, &#39;w&#39;, &#39;r&#39;, &#39;k&#39;, &#39;h&#39;, &#39; &#39;, &#39;沐&#39;, &#39;雨&#39;, &#39;云&#39;, &#39;楼&#39;]

    def test_tuple(self):
        list = [&#39;iworkh&#39;, &#39;沐雨云楼&#39;]
        print(tuple(list))  # (&#39;iworkh&#39;, &#39;沐雨云楼&#39;)

    def test_set(self):
        set1 = {1, 2, 3}
        list = [3, 4, 5]
        set2 = set(list)
        print(set1 &amp; set2)  # 交集：{3}
        print(set1 | set2)  # 并集：{1, 2, 3, 4, 5}
        print(set1 - set2)  # 差集：{1, 2}

    def test_frozenset(self):
        print(frozenset(range(5)))  # frozenset({0, 1, 2, 3, 4})
        list = [&#39;iworkh&#39;, &#39;沐雨云楼&#39;]
        print(frozenset(list))  # frozenset({&#39;沐雨云楼&#39;, &#39;iworkh&#39;})

    def test_sorted(self):
        list = [10, 1, 4, 3, 4]
        print(list)
        print(sorted(list)) # 返回的新list
        print(list)
        print(list.sort()) # 在原来的list上操作
        print(list)</code></pre>
<h3 id="3-3-最值"><a href="#3-3-最值" class="headerlink" title="3-3.最值"></a>3-3.最值</h3><ul>
<li><code>min</code> 函数返回给定参数的最小值，参数可以为序列。</li>
<li><code>max</code> 函数返回给定参数的最大值，参数可以为序列。</li>
</ul>
<p><strong>演示</strong></p>
<pre><code class="python">class MyTestCase(unittest.TestCase):
    def test_min(self):
        print(min(10,2,3,4))  # 2
        print(min([10,2,3,4]))  # 2

    def test_max(self):
        print(max(10,2,3,4))  # 10
        print(max([10,2,3,4]))  # 10</code></pre>
<h3 id="3-4-enumerate"><a href="#3-4-enumerate" class="headerlink" title="3-4.enumerate"></a>3-4.enumerate</h3><p><code>enumerate()</code>函数用于将一个可遍历的数据对象(如列表、元组或字符串)组合为一个索引序列，同时列出数据和数据下标，一般用在 for 循环当中。</p>
<p>语法：<code>enumerate(sequence, [start=0])</code></p>
<ul>
<li>sequence: 一个序列、迭代器或其他支持迭代对象。</li>
<li>start: 下标起始位置。</li>
</ul>
<p><strong>演示</strong></p>
<pre><code class="python">class MyTestCase(unittest.TestCase):
    def test_enumerate(self):
        list_data = [&#39;a&#39;, &#39;b&#39;, &#39;c&#39;]
        e = enumerate(list_data, 0)
        for index, item in e:
            print(&quot;{} --- {}&quot;.format(index, item))</code></pre>
<h3 id="3-5-reversed"><a href="#3-5-reversed" class="headerlink" title="3-5.reversed"></a>3-5.reversed</h3><p><code>reversed</code> 函数返回一个反转的迭代器。</p>
<p><strong>演示</strong></p>
<pre><code class="python">class MyTestCase(unittest.TestCase):
    def test_reversed(self):
        list_data = [1, 2, 3, 4]
        reversed_iter = reversed(list_data)  # 返回是iter
        print(list(reversed_iter)) # [4, 3, 2, 1]

        seqString = &#39;iworkh&#39;
        print(list(reversed(seqString))) # [&#39;h&#39;, &#39;k&#39;, &#39;r&#39;, &#39;o&#39;, &#39;w&#39;, &#39;i&#39;]</code></pre>
<h2 id="4-逻辑判断"><a href="#4-逻辑判断" class="headerlink" title="4.逻辑判断"></a>4.逻辑判断</h2><h3 id="4-1-all"><a href="#4-1-all" class="headerlink" title="4-1.all"></a>4-1.all</h3><p><code>all()</code> 函数用于判断给定的可迭代参数 iterable 中的所有元素是否都为 TRUE，如果是返回 True，否则返回 False。</p>
<blockquote>
<p>元素除了是 0、空、None、False 外都算 True。</p>
</blockquote>
<div class="admonition attention">
<p class="fa admonition-title">注意</p>
<p>
    空元组、空列表返回值为True，这里要特别注意。
</p>
</div>

<p>语法：<code>all(iterable)</code></p>
<blockquote>
<p>iterable: 元组或列表。</p>
</blockquote>
<p><strong>演示</strong></p>
<pre><code class="python">class MyTestCase(unittest.TestCase):
    def test_all(self):
        print(all([]))  # True 空list为true
        print(all(()))  # True 空tuple为true
        print(all((1,2,3,4)))  #True
        print(all([1,0,2])) # False，有0
        print(all([&#39;a&#39;,&#39;&#39;,&#39;c&#39;])) # False， 有空</code></pre>
<h3 id="4-2-any"><a href="#4-2-any" class="headerlink" title="4-2.any"></a>4-2.any</h3><p>any() 函数用于判断给定的可迭代参数 iterable 是否全部为 False，则返回 False，<strong>如果有一个为 True，则返回 True。</strong></p>
<blockquote>
<p>元素除了是 0、空、FALSE 外都算 TRUE。</p>
</blockquote>
<p>语法：<code>any(iterable)</code></p>
<blockquote>
<p>iterable – 元组或列表。</p>
</blockquote>
<p><strong>演示</strong></p>
<pre><code class="python">class MyTestCase(unittest.TestCase):
    def test_any(self):
        print(any([]))  # False 空list为False
        print(any(()))  # False 空tuple为False
        print(any((0,0)))  # False 都0
        print(any([&#39;&#39;,&#39;&#39;,&#39;&#39;]))  # False 都空
        print(any((1,2,3,4)))  #True
        print(any([0,0,2])) # True，有2
        print(any([&#39;a&#39;,&#39;&#39;,&#39;c&#39;])) # True， 有值</code></pre>
<h2 id="5-反射"><a href="#5-反射" class="headerlink" title="5.反射"></a>5.反射</h2><h3 id="5-1-callable"><a href="#5-1-callable" class="headerlink" title="5-1.callable"></a>5-1.callable</h3><p><code>callable()</code> 函数用于检查一个对象是否是可调用的。</p>
<blockquote>
<p>如果返回 True，object 仍然可能调用失败；<br>但如果返回 False，调用对象 object 绝对不会成功。</p>
</blockquote>
<p>对于<strong>函数</strong>、<strong>方法</strong>、<strong>lambda 函式</strong>、 <strong>类</strong>以及<strong>实现了<code>__call__</code>方法的类实例</strong>, 它都返回 True。</p>
<blockquote>
<p>属性为false</p>
</blockquote>
<p><strong>演示</strong></p>
<pre><code class="python">#  函数
def fun_a():
    pass


# 没有实现__call__的类A
class A:
    def method(self):
        pass


# 实现__call__的类B
class B:
    no: str = 1
    _sex: str = &#39;男&#39;

    def __call__(self, *args, **kwargs):
        pass


class MyTestCase(unittest.TestCase):
    def test_call(self):
        # str、list、number
        print(callable(0))  # False
        print(callable(&#39;aaaa&#39;))  # False
        print(callable([1, 2, 3]))  # False
        print(callable((1, 2, 3)))  # False
        # 函数
        print(callable(fun_a))  # True

        # 类属性
        print(callable(B.no))  # False 属性
        print(callable(B._sex))  # False 属性
        # 方法
        print(callable(A.method))  # True
        # 类
        print(callable(A))  # True
        print(callable(B))  # True
        # 对象
        a = A()
        print(callable(a))  # False 没实现`__call__`方法
        b = B()
        print(callable(b))  # True 实现了`__call__`方法

        print(callable(b.no))  # False 属性
        print(callable(b._sex))  # False 属性
        pass</code></pre>
<h3 id="5-2-classmethod"><a href="#5-2-classmethod" class="headerlink" title="5-2.classmethod"></a>5-2.classmethod</h3><p><code>classmethod</code> 修饰符对应的函数不需要实例化，不需要 self 参数。<br>但第一个参数需要是表示自身类的cls参数，可以来调用类的属性，类的方法，实例化对象等。</p>
<blockquote>
<p>要跟后面介绍的staticmethod区分开。</p>
</blockquote>
<p><strong>演示</strong></p>
<pre><code class="python">class A(object):
    bar = 1
    def func1(self):
        print (&#39;foo&#39;)

    @classmethod
    def func2(cls):
        print (&#39;func2&#39;)
        print (cls.bar)
        cls().func1()   # 调用 func1 方法


class MyTestCase(unittest.TestCase):
    def test_classmethod(self):
        A.func2()</code></pre>
<h3 id="5-3-compile"><a href="#5-3-compile" class="headerlink" title="5-3.compile"></a>5-3.compile</h3><p><code>compile()</code> 函数将一个字符串编译为字节代码。</p>
<p>语法：<code>compile(source, filename, mode[, flags[, dont_inherit]])</code></p>
<ul>
<li>source – 字符串或者AST（Abstract Syntax Trees）对象。</li>
<li>filename – 代码文件名称，如果不是从文件读取代码则传递一些可辨认的值。</li>
<li>mode – 指定编译代码的种类。可以指定为 exec, eval, single。</li>
<li>flags – 变量作用域，局部命名空间，如果被提供，可以是任何映射对象。。</li>
<li>flags和dont_inherit是用来控制编译源码时的标志</li>
</ul>
<p><strong>演示</strong></p>
<pre><code class="python">class MyTestCase(unittest.TestCase):
    def test_compile(self):
        # exec
        source = &quot;for i in range(1,5): print(i)&quot;
        compiled_source = compile(source, &#39;&#39;, &#39;exec&#39;)
        exec(compiled_source)
        # eval
        str = &quot;3 * 4 + 5&quot;
        compiled_eval = compile(str, &#39;&#39;, &#39;eval&#39;)
        result = eval(compiled_eval)
        print(result)</code></pre>
<blockquote>
<p><code>exec</code> 和<code>eval</code> 后面会讲解</p>
</blockquote>
<h3 id="5-4-dir"><a href="#5-4-dir" class="headerlink" title="5-4.dir"></a>5-4.dir</h3><p><code>dir()</code> </p>
<ul>
<li>函数不带参数时，返回<strong>当前范围内的变量</strong>、<strong>方法和定义的类型列表</strong>；</li>
<li>带参数时，返回<strong>参数的属性</strong>、<strong>方法列表</strong>。<blockquote>
<p>如果参数包含方法<strong>dir</strong>()，该方法将被调用。如果参数不包含<strong>dir</strong>()，该方法将最大限度地收集参数信息。</p>
</blockquote>
</li>
</ul>
<p><strong>演示</strong></p>
<pre><code class="python">class User:
    name: str = &#39;iworkh&#39;

    def say(self):
        pass

class MyTestCase(unittest.TestCase):
    def test_dir(self):
        # 空
        print(dir())
        # list
        print(dir([]))
        #  str
        print(dir(&#39;a&#39;))
        # 对象
        print(dir(User)) #属性和方法都出来)</code></pre>
<p><strong>只贴一个list的结果，其他得不贴了</strong></p>
<pre><code class="txt">[&#39;__add__&#39;, &#39;__class__&#39;, &#39;__contains__&#39;, &#39;__delattr__&#39;, &#39;__delitem__&#39;, &#39;__dir__&#39;, &#39;__doc__&#39;,
 &#39;__eq__&#39;, &#39;__format__&#39;, &#39;__ge__&#39;, &#39;__getattribute__&#39;, &#39;__getitem__&#39;, &#39;__gt__&#39;, &#39;__hash__&#39;, 
 &#39;__iadd__&#39;, &#39;__imul__&#39;, &#39;__init__&#39;, &#39;__init_subclass__&#39;, &#39;__iter__&#39;, &#39;__le__&#39;, &#39;__len__&#39;, 
 &#39;__lt__&#39;, &#39;__mul__&#39;, &#39;__ne__&#39;, &#39;__new__&#39;, &#39;__reduce__&#39;, &#39;__reduce_ex__&#39;, &#39;__repr__&#39;, 
 &#39;__reversed__&#39;, &#39;__rmul__&#39;, &#39;__setattr__&#39;, &#39;__setitem__&#39;, &#39;__sizeof__&#39;, &#39;__str__&#39;, 
 &#39;__subclasshook__&#39;, &#39;append&#39;, &#39;clear&#39;, &#39;copy&#39;, &#39;count&#39;, &#39;extend&#39;, &#39;index&#39;, &#39;insert&#39;, 
 &#39;pop&#39;, &#39;remove&#39;, &#39;reverse&#39;, &#39;sort&#39;]</code></pre>
<h3 id="5-5-delattr"><a href="#5-5-delattr" class="headerlink" title="5-5.delattr"></a>5-5.delattr</h3><p><code>delattr()</code> 函数用于删除属性。</p>
<p>语法：<code>delattr(object, name)</code></p>
<ul>
<li>object: 对象。</li>
<li>name: 必须是对象的属性</li>
</ul>
<p><code>delattr(x, &#39;filedname&#39;)</code> 相等于 <code>del x.filename</code></p>
<p><strong>演示</strong></p>
<pre><code class="python">class MyTestCase(unittest.TestCase):
    def test_delattr(self):
        user = User()
        user.name = &#39;iworkh&#39;
        user.password = &#39;iworkh123&#39;
        user.age = 10
        print(user.__dict__)
        delattr(user, &#39;password&#39;) # 等价于 del user.password
        print(user.__dict__)
</code></pre>
<h3 id="5-6-eval"><a href="#5-6-eval" class="headerlink" title="5-6.eval"></a>5-6.eval</h3><p><code>eval()</code> 函数用来执行一个字符串表达式，并返回表达式的值。</p>
<p>语法：<code>eval(expression[, globals[, locals]])</code></p>
<ul>
<li>expression – 表达式。</li>
<li>globals – 变量作用域，全局命名空间，如果被提供，则必须是一个字典对象。</li>
<li>locals – 变量作用域，局部命名空间，如果被提供，可以是任何映射对象。</li>
</ul>
<p><strong>演示</strong></p>
<pre><code class="python">class MyTestCase(unittest.TestCase):
    def test_eval(self):
        x = 8
        print(eval(&#39;x+3&#39;))
        print(eval(&#39;7*3&#39;))</code></pre>
<h3 id="5-7-exec"><a href="#5-7-exec" class="headerlink" title="5-7.exec"></a>5-7.exec</h3><p><code>exec()</code>执行储存在字符串或文件中的 Python 语句，相比于 eval，exec可以执行更复杂的 Python 代码。</p>
<p>语法：<code>exec(object[, globals[, locals]])</code></p>
<ul>
<li>object：必选参数，表示需要被指定的Python代码。它必须是<strong>字符串</strong>或<strong>code对象</strong>。<ul>
<li>如果object是一个字符串，该字符串会先被解析为一组Python语句，然后再执行（除非发生语法错误）。</li>
<li>如果object是一个code对象，那么它只是被简单的执行。</li>
</ul>
</li>
<li>globals：可选参数，表示全局命名空间（存放全局变量），如果被提供，则必须是一个字典对象。</li>
<li>locals：可选参数，表示当前局部命名空间（存放局部变量），如果被提供，可以是任何映射对象。如果该参数被忽略，那么它将会取与globals相同的值。</li>
</ul>
<p><strong>演示</strong></p>
<pre><code class="python">class MyTestCase(unittest.TestCase):
    def test_exec(self):
        # 普通字符串
        exec(&#39;print(&quot;Hello World&quot;)&#39;)

        # 有参数，使用dict传入
        source = &quot;&quot;&quot;for i in range(num):
                    print (&quot;iter time: %d&quot; % i)
            &quot;&quot;&quot;
        exec(source, {&#39;num&#39;: 5})
</code></pre>
<h3 id="5-8-filter"><a href="#5-8-filter" class="headerlink" title="5-8.filter"></a>5-8.filter</h3><p><code>filter()</code>函数用于过滤序列，过滤掉不符合条件的元素，<strong>返回一个迭代器对象</strong>，如果要转换为列表，可以使用 list() 来转换。</p>
<p>语法：<code>filter(function, iterable)</code></p>
<ul>
<li>function – 判断函数。</li>
<li>iterable – 可迭代对象。<blockquote>
<p>序列的每个元素作为参数传递给函数进行判，然后返回 True 或 False，最后将返回 True 的元素放到新列表中。</p>
</blockquote>
</li>
</ul>
<p><strong>演示</strong></p>
<pre><code class="python">def is_odd(n):
    return n % 2 == 1

class MyTestCase(unittest.TestCase):
    def test_filter(self):
        list_data = list(range(1, 10))
        # lambda
        result = filter(lambda item: item % 2 == 0, list_data) # 返回的是iter
        print(list(result)) # [2, 4, 6, 8]
        # func
        result2 = filter(is_odd, list_data)
        print(list(result2)) # [1, 3, 5, 7, 9]</code></pre>
<h3 id="5-9-getattr"><a href="#5-9-getattr" class="headerlink" title="5-9.getattr"></a>5-9.getattr</h3><p><code>getattr()</code> 函数用于返回一个对象属性值。</p>
<p>语法：<code>getattr(object, name[, default])</code></p>
<ul>
<li>object – 对象。</li>
<li>name – 字符串，对象属性。</li>
<li>default – 默认返回值，如果不提供该参数，在没有对应属性时，将触发 AttributeError。</li>
</ul>
<p><strong>演示</strong></p>
<pre><code class="python">class MyTestCase(unittest.TestCase):
    def test_getattr(self):
        user = User()
        user.name = &#39;iworkh&#39;
        user.age = 20
        getattr(user, &#39;name&#39;)</code></pre>
<h3 id="5-10-globals"><a href="#5-10-globals" class="headerlink" title="5-10.globals"></a>5-10.globals</h3><p><code>globals()</code> 函数会以字典类型返回当前位置的全部全局变量。</p>
<p><strong>演示</strong></p>
<pre><code class="python">global_a = 10
global_b = &#39;iworkh&#39;


class MyTestCase(unittest.TestCase):
    def test_globals(self):
        # globals 函数返回一个全局变量的字典，包括所有导入的变量。
        all_globals = globals()
        print(all_globals[&#39;global_b&#39;])</code></pre>
<h3 id="5-11-hasattr"><a href="#5-11-hasattr" class="headerlink" title="5-11.hasattr"></a>5-11.hasattr</h3><p><code>hasattr()</code> 函数用于判断对象是否包含对应的属性和方法。</p>
<p>语法：<code>hasattr(object, name)</code></p>
<ul>
<li>object – 对象。</li>
<li>name – 字符串，属性名。</li>
</ul>
<p><strong>演示</strong></p>
<pre><code class="python">class User:
    name: str
    age: int

    def say(self):
        pass


class MyTestCase(unittest.TestCase):
    def test_hasattr(self):
        user = User()
        user.name = &#39;iworkh&#39;
        user.age = 120
        print(hasattr(user, &#39;name&#39;))  # True 属性
        print(hasattr(user, &#39;sex&#39;))  # False
        print(hasattr(user, &#39;say&#39;))  # True 方法</code></pre>
<h3 id="5-12-hash"><a href="#5-12-hash" class="headerlink" title="5-12.hash"></a>5-12.hash</h3><p><code>hash()</code>用于获取一个对象（字符串或者数值等）的哈希值。</p>
<blockquote>
<p>函数可以应用于<strong>数字</strong>、<strong>字符串</strong>和<strong>对象</strong>，不能直接应用于 list、set、dictionary。</p>
</blockquote>
<p><strong>演示</strong></p>
<pre><code class="python">class User:
    name: str
    age: int


class MyTestCase(unittest.TestCase):
    def test_hash(self):
        print(hash(1))
        # 字符串
        print(hash(&quot;2&quot;))
        # tuple
        print(hash((1, False, &#39;3&#39;)))
        # dict要转str
        print(hash(str({&#39;name&#39;: &#39;iworkh&#39;, &#39;age&#39;: 20})))
        # 对象
        user = User()
        user.name = &#39;iworkh&#39;
        user.age = 120
        print(hash(user))</code></pre>
<h3 id="5-13-id"><a href="#5-13-id" class="headerlink" title="5-13.id"></a>5-13.id</h3><p><code>id()</code> 函数返回对象的唯一标识符，标识符是一个整数。</p>
<blockquote>
<p>CPython 中 id() 函数用于获取对象的内存地址。</p>
</blockquote>
<p><strong>演示</strong></p>
<pre><code class="python">class User:
    name: str
    age: int


class MyTestCase(unittest.TestCase):
    def test_id(self):
        print(id(1))
        # 字符串
        print(id(&quot;2&quot;))
        # tuple
        print(id((1, False, &#39;3&#39;)))
        # list
        print(id([1, False, &#39;3&#39;]))
        # dict
        print(id({&#39;name&#39;: &#39;iworkh&#39;, &#39;age&#39;: 20}))
        # 对象
        user = User()
        user.name = &#39;iworkh&#39;
        user.age = 120
        print(id(user))</code></pre>
<h3 id="5-14-isinstance"><a href="#5-14-isinstance" class="headerlink" title="5-14.isinstance"></a>5-14.isinstance</h3><p><code>isinstance()</code> 函数来判断一个对象是否是一个已知的类型，类似 type()。</p>
<blockquote>
<p>type() 不会认为子类是一种父类类型，不考虑继承关系。<br>isinstance() 会认为子类是一种父类类型，考虑继承关系。</p>
</blockquote>
<p>语法：<code>isinstance(object, classinfo)</code></p>
<ul>
<li>object – 实例对象。</li>
<li>classinfo – 可以是直接或间接类名、基本类型或者由<strong>它们组成的元组(只要一个满足就返回True)</strong>。</li>
</ul>
<p><strong>演示</strong></p>
<pre><code class="python">class People:
    sex: str


class User(People):
    name: str
    age: int


class MyTestCase(unittest.TestCase):
    def test_isinstance(self):
        a = 10
        print(isinstance(a, int))  # True
        print(isinstance(a, float))  # False
        print(isinstance(a, (int, float, str)))  # True 满足一个即可
        # 对象
        print(isinstance(User(), User))  # True
        print(type(User()) == User)  # True
        print(isinstance(User(), People))  # True  isinstance考虑继承
        print(type(User()) == People)  # False type不考虑继承</code></pre>
<h3 id="5-15-issubclass"><a href="#5-15-issubclass" class="headerlink" title="5-15.issubclass"></a>5-15.issubclass</h3><p>issubclass() 方法用于判断参数 class 是否是类型参数 classinfo 的子类。</p>
<p>语法：<code>issubclass(class, classinfo)</code></p>
<ul>
<li>class – 类。</li>
<li>classinfo – 类。<blockquote>
<p>这参数，两个都是类。而前面介绍的<code>isinstance</code>参数，一个是对象，一个是类</p>
</blockquote>
</li>
</ul>
<p><strong>演示</strong></p>
<pre><code class="python">class People:
    sex: str


class User(People):
    name: str
    age: int


class MyTestCase(unittest.TestCase):
    def test_issubclass(self):
        # 对象
        print(issubclass(User, People))  # True</code></pre>
<h3 id="5-16-len"><a href="#5-16-len" class="headerlink" title="5-16.len"></a>5-16.len</h3><p><code>len()</code>方法返回对象（字符、列表、元组等）长度或项目个数。</p>
<p><strong>演示</strong></p>
<pre><code class="python">class MyTestCase(unittest.TestCase):
    def test_len(self):
        # str
        print(len(&#39;iworkh&#39;))
        # list
        print(len([1, 2, 3]))
        # tuple
        print(len((1, 2, 3)))
        # dict
        dict = {&#39;name&#39;: &#39;iworkh&#39;, &#39;age&#39;: 10}
        print(len(dict))
</code></pre>
<h3 id="5-17-locals"><a href="#5-17-locals" class="headerlink" title="5-17.locals"></a>5-17.locals</h3><p><code>locals()</code> 函数会以字典类型返回当前位置的全部局部变量。</p>
<p><strong>演示</strong></p>
<pre><code class="python"> def add(a, b):
     dict = {&#39;name&#39;: &#39;iworkh&#39;, &#39;age&#39;: 10}
     print(locals()) # {&#39;a&#39;: 1, &#39;b&#39;: 3, &#39;dict&#39;: {&#39;name&#39;: &#39;iworkh&#39;, &#39;age&#39;: 10}}
     return a + b


 class MyTestCase(unittest.TestCase):
     def test_locals(self):
         add(1, 3)</code></pre>
<h3 id="5-18-map"><a href="#5-18-map" class="headerlink" title="5-18.map"></a>5-18.map</h3><p><code>map()</code>会根据提供的函数对指定序列做映射。</p>
<p>语法：<code>map(function, iterable, ...)</code></p>
<blockquote>
<p>第一个参数 function 以参数序列中的每一个元素调用 function 函数，返回包含每次 function 函数返回值的新列表。</p>
</blockquote>
<ul>
<li><p>function – 函数</p>
</li>
<li><p>iterable – 一个或多个序列</p>
<p><strong>演示</strong></p>
<pre><code class="python">class MyTestCase(unittest.TestCase):
   def test_map(self):
       list_data = [1, 2, 3, 4]
       result = map(lambda x: x * 2, list_data) # 返回iter
       print(list(result))
</code></pre>
</li>
</ul>
<h3 id="5-19-bytearray"><a href="#5-19-bytearray" class="headerlink" title="5-19.bytearray"></a>5-19.bytearray</h3><p><code>bytearray()</code> 方法返回一个新字节数组。这个数组里的元素是可变的，并且每个元素的值范围: 0 &lt;= x &lt; 256。</p>
<p>语法<code>class bytearray([source[, encoding[, errors]]])</code></p>
<ul>
<li>如果 source 为整数，则返回一个长度为 source 的初始化数组；</li>
<li>如果 source 为字符串，则按照指定的 encoding 将字符串转换为字节序列；</li>
<li>如果 source 为可迭代类型，则元素必须为<code>[0 ,255]</code>中的整数；</li>
<li>如果 source 为与 buffer 接口一致的对象，则此对象也可以被用于初始化 bytearray。</li>
<li>如果没有输入任何参数，默认就是初始化数组为0个元素。</li>
</ul>
<p><strong>演示</strong></p>
<pre><code class="python">class MyTestCase(unittest.TestCase):
    def test_bytearray(self):
        # str
        print(bytearray(&#39;abcde&#39;, &#39;utf-8&#39;))

        # list
        list_data = [1, 2, 3, 4]
        print(bytearray(list_data))</code></pre>
<h3 id="5-20-memoryview"><a href="#5-20-memoryview" class="headerlink" title="5-20.memoryview"></a>5-20.memoryview</h3><p><code>memoryview()</code> 函数返回给定参数的内存查看对象(memory view)。</p>
<blockquote>
<p>所谓内存查看对象，是指对支持缓冲区协议的数据进行包装，在不需要复制对象基础上允许Python代码访问。</p>
</blockquote>
<p>语法：<code>memoryview(obj)</code></p>
<blockquote>
<p>返回值是元组列表。</p>
</blockquote>
<p><strong>演示</strong></p>
<pre><code class="python">class MyTestCase(unittest.TestCase):
    def test_memoryview(self):
        # str
        ba = bytearray(&#39;abcde&#39;, &#39;utf-8&#39;)
        mv = memoryview(ba)
        print(mv[1])  # 98
        print(mv[1:4])  # &lt;memory at 0x000001D28801C948&gt;
        print(mv[1:4].tobytes())  # b&#39;bcd&#39;
        print(mv[-1])  # 101

        print(&quot;*&quot; * 50)

        # list
        list_data = [1, 2, 3, 4]
        ba_list = bytearray(list_data)
        mv_list = memoryview(ba_list)
        print(mv_list[0]) # 1 </code></pre>
<h3 id="5-21-next"><a href="#5-21-next" class="headerlink" title="5-21.next"></a>5-21.next</h3><p><code>next()</code> 返回迭代器的下一个项目。</p>
<blockquote>
<p>next() 函数要和生成迭代器的iter() 函数一起使用。</p>
</blockquote>
<p>语法：<code>next(iterator[, default])</code></p>
<ul>
<li>iterator – 可迭代对象</li>
<li>default – 可选，用于设置在没有下一个元素时返回该默认值，如果不设置，又没有下一个元素则会触发 StopIteration 异常。</li>
</ul>
<p><strong>演示</strong></p>
<pre><code class="python">class MyTestCase(unittest.TestCase):
    def test_next(self):
        list_data = [1, 2, 3, 4]
        it = iter(list_data)
        while (True):
            try:
                data = next(it)
                print(data)
            except StopIteration:
                break</code></pre>
<h3 id="5-22-property"><a href="#5-22-property" class="headerlink" title="5-22.property"></a>5-22.property</h3><p><code>property()</code> 函数的作用是在新式类中返回属性值。</p>
<p>语法：<code>class property([fget[, fset[, fdel[, doc]]]])</code></p>
<ul>
<li>fget – 获取属性值的函数</li>
<li>fset – 设置属性值的函数</li>
<li>fdel – 删除属性值函数</li>
<li>doc – 属性描述信息</li>
</ul>
<p><strong>演示</strong></p>
<p>对象里有个私有属性，然后通过方法来执行塞值、取值、删除操作</p>
<p><strong>通过方法调用</strong></p>
<pre><code class="python">class User:
    _name: str

    def get_name(self):
        print(&#39;call method ... get_name&#39;)
        return self._name

    def set_name(self, value):
        print(&#39;call method ... set_name&#39;)
        self._name = value

    def del_name(self):
        print(&#39;call method ... del_name&#39;)
        del self._name


class MyTestCase(unittest.TestCase):
    def test_method(self):
        # 对象.方法
        user = User()
        user.set_name(value=&#39;iworkh&#39;)
        print(user.get_name())</code></pre>
<p><strong>通过property方式</strong></p>
<pre><code class="python">class User:
    _name: str

    def get_name(self):
        print(&#39;call method ... get_name&#39;)
        return self._name

    def set_name(self, value):
        print(&#39;call method ... set_name&#39;)
        self._name = value

    def del_name(self):
        print(&#39;call method ... del_name&#39;)
        del self._name


    name = property(get_name, set_name, del_name, &#39;姓名&#39;)


class MyTestCase(unittest.TestCase):

    def test_property(self):
        # property
        user2 = User()
        user2.name=&#39;iworkh&#39;
        print(user2.name)</code></pre>
<blockquote>
<p>添加<code>name = property(get_name, set_name, del_name, &#39;姓名&#39;)</code>定义</p>
</blockquote>
<p><strong>使用装饰器</strong></p>
<pre><code class="python">class User2:
    _name: str

    @property
    def name(self):
        &quot;&quot;&quot;
        姓名
        &quot;&quot;&quot;
        print(&#39;call2 method ... get_name&#39;)
        return self._name

    @name.setter
    def name(self, value):
        print(&#39;call2 method ... set_name&#39;)
        self._name = value

    @name.deleter
    def name(self):
        print(&#39;call2 method ... del_name&#39;)
        del self._name

class MyTestCase(unittest.TestCase):
    def test_anno(self):
        # property
        user2 = User2()
        user2.name = &#39;iworkh&#39;
        print(user2.name)</code></pre>
<blockquote>
<p>使用<code>@property</code>对应的方法名<code>name</code>就是属性名<code>name</code>，然后再对对应的setter和getter方法设置<code>@name.setter</code>和<code>@name.deleter</code></p>
</blockquote>
<h3 id="5-23-vars"><a href="#5-23-vars" class="headerlink" title="5-23.vars"></a>5-23.vars</h3><p><code>vars()</code>函数返回对象object的<strong>属性和属性值的字典对象</strong>。</p>
<p><strong>演示</strong></p>
<pre><code class="python">class User:
    name: str
    age: int


class MyTestCase(unittest.TestCase):
    def test_vars(self):
        # 对象
        user = User()
        user.name = &#39;iworkh&#39;
        user.age = 11
        print(vars(user)) # {&#39;name&#39;: &#39;iworkh&#39;, &#39;age&#39;: 11}
</code></pre>
<h3 id="5-24-setattr"><a href="#5-24-setattr" class="headerlink" title="5-24.setattr"></a>5-24.setattr</h3><p><code>setattr()</code> 函数对应函数 getattr()，用于设置属性值，该属性不一定是存在的。</p>
<p>语法：<code>setattr(object, name, value)</code></p>
<ul>
<li>object – 对象。</li>
<li>name – 字符串，对象属性。</li>
<li>value – 属性值。</li>
</ul>
<p><strong>演示</strong></p>
<pre><code class="python">class User:
    name: str
    age: int


class MyTestCase(unittest.TestCase):
    def test_setattr(self):
        # 对象
        user = User()
        user.name = &#39;iworkh&#39;
        # 存在属性赋值
        setattr(user, &#39;age&#39;, 20)
        print(user.age) # 20
        # 不存在属性赋值
        setattr(user, &#39;sex&#39;, &#39;男&#39;)
        print(user.sex) # 男</code></pre>
<h3 id="5-25-slice"><a href="#5-25-slice" class="headerlink" title="5-25.slice"></a>5-25.slice</h3><p><code>slice()</code> 函数实现切片对象，主要用在切片操作函数里的参数传递。</p>
<p>语法： <code>slice(stop)</code>或 <code>slice(start, stop[, step])</code></p>
<p><strong>演示</strong></p>
<pre><code class="python">class MyTestCase(unittest.TestCase):
    def test_type(self):
        slice_end = slice(3)
        print(slice_end)
        data = range(10)
        print(data[slice_end])</code></pre>
<h3 id="5-26-staticmethod"><a href="#5-26-staticmethod" class="headerlink" title="5-26.staticmethod"></a>5-26.staticmethod</h3><p><code>staticmethod</code> 返回函数的静态方法。</p>
<blockquote>
<p>既实现实例化使用 <code>C().f()</code>，也可以不实例化调用该方法 <code>C.f()</code>。</p>
</blockquote>
<blockquote>
<p>要跟前面介绍的classmethod区分开。</p>
</blockquote>
<p><strong>区别</strong></p>
<ul>
<li>如果方法不需要访问对象/类的属性或其他方法的话，那么使用staticmethod</li>
<li>如果需要方法类的属性或其他方法的话，那么使用classmethod</li>
<li>classmethod的方法第一个参数是<code>cls</code></li>
</ul>
<p><strong>演示</strong></p>
<pre><code class="pyton">class A(object):
    @staticmethod
    def add(a, b):
        return a + b


class MyTestCase(unittest.TestCase):
    def test_staticmethod(self):
        # 类调用
        print(A.add(2, 4))
        # 对象调用
        a = A()
        print(a.add(2, 6))</code></pre>
<h3 id="5-27-type"><a href="#5-27-type" class="headerlink" title="5-27.type"></a>5-27.type</h3><p><code>type()</code> 函数如果你只有第一个参数则返回对象的类型，三个参数返回新的类型对象。</p>
<p><strong>isinstance() 与 type() 区别：</strong></p>
<ul>
<li>type() 不会认为子类是一种父类类型，不考虑继承关系。</li>
<li>isinstance() 会认为子类是一种父类类型，考虑继承关系。</li>
</ul>
<p>语法：<code>type(object)</code> 或 <code>type(name, bases, dict)</code></p>
<ul>
<li>name – 类的名称。</li>
<li>bases – 基类的元组。</li>
<li>dict – 字典，类内定义的命名空间变量。</li>
</ul>
<p><strong>演示</strong></p>
<pre><code class="python">class MyTestCase(unittest.TestCase):
    def test_type(self):
        # int
        print(type(10))  # &lt;class &#39;int&#39;&gt;
        # list
        print(type([1, 2, 3]))  # &lt;class &#39;list&#39;&gt;</code></pre>
<h3 id="5-28-repr"><a href="#5-28-repr" class="headerlink" title="5-28.repr"></a>5-28.repr</h3><p><code>repr()</code> 函数将对象转化为供解释器读取的形式。</p>
<blockquote>
<p>不怎么用</p>
</blockquote>
<p><strong>演示</strong></p>
<pre><code class="python">class User:
    name: str
    age: int


class MyTestCase(unittest.TestCase):
    def test_repr(self):
        # str
        name = &#39;iwrokh&#39;
        print(name)
        print(repr(name))

        # list
        list_data = [1, 2, 3, 4]
        print(list_data)
        print(repr(list_data))

        # dict
        dict = {&#39;name&#39;: &#39;iworkh&#39;, &#39;age&#39;: 19}
        print(dict)
        print(repr(dict))

        # obj
        user = User
        user.name = &#39;iworkh&#39;
        user.age = 11
        print(user)
        print(repr(user))</code></pre>
<h3 id="5-29-zip"><a href="#5-29-zip" class="headerlink" title="5-29.zip"></a>5-29.zip</h3><p><code>zip()</code> 函数用于将可迭代的对象作为参数，将对象中对应的元素打包成一个个元组，然后返回由这些元组组成的对象，这样做的好处是节约了不少的内存。</p>
<blockquote>
<p>如果各个迭代器的元素个数不一致，则返回列表长度与最短的对象相同，利用 * 号操作符，可以将元组解压为列表。</p>
</blockquote>
<p><strong>演示</strong></p>
<pre><code class="python">class MyTestCase(unittest.TestCase):
    def test_zip(self):
        a = [1, 2, 3]
        b = [4, 5, 6]
        c = [4, 5, 6, 7, 8]
        zip_tuple = zip(a, b)
        print(list(zip_tuple))
        print(list(zip(a, c)))  # 元素个数与最短的列表一致

        # 与 zip 相反，zip(*) 可理解为解压，返回二维矩阵式
        x, y = zip(*zip(a, c))  # 可以
        print(list(x))
        print(list(y))

        # m, n = zip(*zip_tuple)  # 报错 not enough values to unpack，上面有调用了list(zip_tuple)就会报错
        zip_tuple2 = zip(a, b)
        m, n = zip(*zip_tuple2) # 正确，没有对zip(a, b)的结果进行list转化
        print(list(m))
        print(list(n))</code></pre>
<div class="admonition attention">
<p class="fa admonition-title">警告</p>
<p>
    使用zip(*)时候，如果参数是前面定义过的变量的话，那么最好不要对变量做一些操作，可能导致zip(*)失败。
    可以能原因，在list()的时候，对源对象进行了特殊处理，导致了后面使用zip(*)的时候失败。
</p>
</div>

<blockquote>
<p>这还有一篇stackoverflow也遇到这错。<a href="https://stackoverflow.com/questions/33418903/python-valueerror-not-enough-values-to-unpack-expected-2-got-0" target="_blank" rel="noopener">stackoverflow里not enough values to unpack的错误</a>有兴趣的可以取研究下</p>
</blockquote>
<h3 id="5-30-xrange"><a href="#5-30-xrange" class="headerlink" title="5-30.xrange"></a>5-30.xrange</h3><p>python2 <code>xrange()</code> 函数用法与 range 完全相同，所不同的是生成的不是一个数组，而是一个生成器。</p>
<p>python3中没有了，就用range</p>
<h2 id="6-IO操作"><a href="#6-IO操作" class="headerlink" title="6.IO操作"></a>6.IO操作</h2><h3 id="6-1-input"><a href="#6-1-input" class="headerlink" title="6-1.input"></a>6-1.input</h3><p><code>input()</code> 函数接受一个标准输入数据，返回为 string 类型。</p>
<p><strong>演示</strong></p>
<pre><code class="python">class MyTestCase(unittest.TestCase):
    def test_input(self):
        a = input(&quot;input:&quot;)
        print(a)</code></pre>
<h3 id="6-2-open"><a href="#6-2-open" class="headerlink" title="6-2.open"></a>6-2.open</h3><p><code>open()</code>函数用于打开一个文件，并返回文件对象，在对文件进行处理过程都需要使用到这个函数，如果该文件无法被打开，会抛出 OSError。</p>
<blockquote>
<p>使用 open() 函数一定要保证关闭文件对象，即调用 close() 函数。</p>
</blockquote>
<p>语法：<code>open(file, mode=&#39;r&#39;, buffering=-1, encoding=None, errors=None, newline=None, closefd=True, opener=None)</code></p>
<ul>
<li>file: 必需，文件路径（相对或者绝对路径）。</li>
<li>mode: 可选，文件打开模式(<code>r</code>: 读；<code>x</code>:写； <code>a</code>:追加；<code>b</code>:二进制； <code>+</code>:打开一个文件进行更新，可读可写)</li>
<li>buffering: 设置缓冲</li>
<li>encoding: 一般使用utf8</li>
<li>errors: 报错级别</li>
<li>newline: 区分换行符</li>
<li>closefd: 传入的file参数类型</li>
<li>opener: </li>
</ul>
<blockquote>
<p>默认为文本模式，如果要以二进制模式打开，加上 b 。</p>
</blockquote>
<p><strong>演示</strong></p>
<pre><code class="python">class MyTestCase(unittest.TestCase):
    def test_open(self):
        f = open(&#39;file_buildin_func.py&#39;)
        try:
            data = f.read()
            print(data)
        except Exception as e:
            print(e)
        finally:
            f.close()</code></pre>
<h3 id="6-3-print"><a href="#6-3-print" class="headerlink" title="6-3.print"></a>6-3.print</h3><p>print() 方法用于打印输出，最常见的一个函数。</p>
<p>语法: <code>print(*objects, sep=&#39; &#39;, end=&#39;\n&#39;, file=sys.stdout, flush=False)</code></p>
<ul>
<li>objects – 复数，表示可以一次输出多个对象。输出多个对象时，需要用 , 分隔。</li>
<li>sep – 用来间隔多个对象，默认值是一个空格。</li>
<li>end – 用来设定以什么结尾。默认值是换行符 \n，我们可以换成其他字符串。</li>
<li>file – 要写入的文件对象。</li>
<li>flush – 输出是否被缓存通常决定于 file，但如果 flush 关键字参数为 True，流会被强制刷新。</li>
</ul>
<p><strong>演示</strong></p>
<pre><code class="python">class MyTestCase(unittest.TestCase):
    def test_print(self):
        print(&quot;xxx&quot;)
        print(&quot;aaa&quot;&quot;bbb&quot;)
        print(&quot;aaa&quot;,&quot;bbb&quot;)
        print(&quot;https://&quot;,&quot;www&quot;,&quot;iworkh&quot;,&quot;com&quot;,sep=&#39;.&#39;)</code></pre>
<h2 id="7-其他"><a href="#7-其他" class="headerlink" title="7.其他"></a>7.其他</h2><h3 id="7-1-help"><a href="#7-1-help" class="headerlink" title="7-1.help"></a>7-1.help</h3><p><code>help()</code> 函数用于查看函数或模块用途的详细说明。</p>
<p><strong>演示</strong></p>
<pre><code class="python">class MyTestCase(unittest.TestCase):
    def test_help(self):
        help(str)
        help(list)
        list_data = [1, 2, 3]
        help(list_data)
        help(list_data.append)</code></pre>
<h3 id="7-2-import"><a href="#7-2-import" class="headerlink" title="7-2.import"></a>7-2.import</h3><p><code>__import__()</code> 函数用于动态加载类和函数 。</p>
<blockquote>
<p>如果一个模块经常变化就可以使用<code>__import__()</code>来动态载入。</p>
</blockquote>
<p><strong>演示</strong></p>
<p>定义两个模块，供不同情况使用时候动态引用</p>
<p><strong>dark类</strong></p>
<pre><code class="python">import os

print(&#39;this is a dark theme {}&#39;.format(id(os)))</code></pre>
<blockquote>
<p>文件路径: <code>theme/dark/import_dark_buildin_func.py</code></p>
</blockquote>
<p><strong>light类</strong></p>
<pre><code class="python">import os

print(&#39;this is a light theme {}&#39;.format(id(os)))</code></pre>
<blockquote>
<p>文件路径: <code>theme/light/import_light_buildin_func.py</code></p>
</blockquote>
<p><strong>测试类</strong></p>
<pre><code class="python">class MyTestCase(unittest.TestCase):
    def test_import(self):
        theme = &#39;dark&#39;
        # theme = &#39;light&#39;
        if theme == &#39;dark&#39;:
            __import__(&#39;theme.dark.import_dark_buildin_func&#39;)
        else:
            __import__(&#39;theme.light.import_light_buildin_func&#39;)

        print(&#39;done&#39;)</code></pre>
<h2 id="8-总结"><a href="#8-总结" class="headerlink" title="8.总结"></a>8.总结</h2><p>内置函数有很多，只要记得一些常用的即可，其他用的时候可以查表格即可。但是一些特殊内置函数要注意区别。</p>
<p>思考：</p>
<ul>
<li>1.staticmehtod和classmethod使用和区别</li>
<li>2.setattr、getattr、delattr、hasattr使用</li>
<li>3.类型转化：int、str、float、list、dict、tuple、iter 的使用</li>
<li>4.isinstance、issubclass、type的使用和区别</li>
<li>5.format、print、open如何使用</li>
<li>6.sorted、reversed、max、min、len、sum使用</li>
<li>7.map、filter、zip使用</li>
<li>8.dir、call使用</li>
</ul>
<p>如果上面几个问题能过回答上，那么恭喜您，本节内容的精髓您都掌握了。</p>
<blockquote>
<p>掌握上面一些常用基本够用了，其他用的时候再出来查即可，下一篇再来看下 <a href="https://iworkh.gitee.io/blog/2020/06/25/python-tool-buildin-attr/">内置属性</a></p>
</blockquote>

      
       <hr><span style="font-style: italic;color: gray;"> 转载请注明来源，欢迎指出任何有错误或不够清晰的表达。可以在下面评论区评论，也可以邮件至 157162006@qq.com </span>
    </div>
</article>


<p>
    <a  class="dashang" onclick="dashangToggle()">赏</a>
</p>


<div class="article_copyright">
    <p><span class="copy-title">文章标题:</span>👍python内置函数</p>
    <p><span class="copy-title">字数:</span><span class="post-count">8.4k</span></p>
    <p><span class="copy-title">本文作者:</span><a  title="沐雨云楼">沐雨云楼</a></p>
    <p><span class="copy-title">发布时间:</span>2020-06-24, 18:31:59</p>
    <p><span class="copy-title">最后更新:</span>2020-09-12, 21:21:47</p>
    <span class="copy-title">原始链接:</span><a class="post-url" href="/blog/2020/06/24/python-tool-buildin-func/" title="👍python内置函数">https://iworkh.gitee.io/blog/2020/06/24/python-tool-buildin-func/</a>
    <p>
        <span class="copy-title">版权声明:</span><i class="fa fa-creative-commons"></i> <a rel="license noopener" href="http://creativecommons.org/licenses/by-nc-sa/4.0/" target="_blank" title="CC BY-NC-SA 4.0 International" target = "_blank">&#34;署名-非商用-相同方式共享 4.0&#34;</a> 转载请保留原文链接及作者。
    </p>
</div>



    <div id="comments"></div>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/gitalk@1/dist/gitalk.css">

<script type="text/javascript">
    $.getScript('/blog/js/gitalk.js', function () {
        var gitalk = new Gitalk({
            clientID: 'e4a269e1ae1600031361',
            clientSecret: '6f3f981cbc49dd802fde779697d8f01da3a77981',
            repo: 'iworkh.github.io',
            owner: 'iworkh',
            admin: ['iworkh'],
            id: decodeURI(location.pathname),
            distractionFreeMode: 'true',
            language: 'zh-CN',
            perPage: parseInt('10',10)
        })
        gitalk.render('comments')
    })
</script>




    




    </div>
    <div class="copyright">
        <p class="footer-entry">©2020 iworkh</p>
<!--<p class="footer-entry">Built with <a href="https://hexo.io/" target="_blank">Hexo</a> and <a href="https://github.com/yelog/hexo-theme-3-hexo" target="_blank">3-hexo</a> theme</p>-->

    </div>
    <div class="full-toc">
        <button class="full" data-title="切换全屏 快捷键 s"><span class="min "></span></button>
<button class="post-toc-menu" data-title="打开TOC 快捷键 w"><span class="post-toc-menu-icons"></span></button>
<div class="post-toc"><span class="post-toc-title">目录</span>
    <div class="post-toc-content">

    </div>
</div>
<a class="" id="rocket" ></a>

    </div>
</div>
<div class="acParent"></div>

<div class="hide_box" onclick="dashangToggle()"></div>
<div class="shang_box">
    <a class="shang_close"  onclick="dashangToggle()">×</a>
    <div class="shang_tit">
        <p>喜欢就点赞,疼爱就打赏</p>
    </div>
    <div class="shang_payimg">
        <div class="pay_img">
            <img src="/blog/img/alipay.jpg" class="alipay" title="扫码支持">
            <img src="/blog/img/weixin.jpg" class="weixin" title="扫码支持">
        </div>
    </div>
    <div class="shang_payselect">
        <span><label><input type="radio" name="pay" checked value="alipay">支付宝</label></span><span><label><input type="radio" name="pay" value="weixin">微信</label></span>
    </div>
</div>


</body>
<script src="/blog/js/jquery.pjax.js?v=1.0.1" ></script>

<script src="/blog/js/script.js?v=1.0.1" ></script>
<script>
    var img_resize = 'default';
    /*作者、标签的自动补全*/
    $(function () {
        $('.search').AutoComplete({
            'data': ['@沐雨云楼','@iworkh','#ai','#attr','#aysnc','#beanmap','#bigdecimal','#blog','#chrome','#dict','#dll','#docker','#domain','#fastjson','#func','#git','#github','#hadoop','#hexo','#idea','#iworkh','#jackson','#java','#jdni','#jfinalshell','#joplin','#JPA','#lock','#markdowm','#maven','#mock','#mq','#mycat','#mysql','#nginx','#notebook','#plan','#powermock','#python','#redis','#rest','#sharding-jdbc','#spark','#springboot','#test','#tool','#tools','#tornado','#transactional','#web','#windows','#wtforms','#zookeeper','#分库分表','#分页','#命令','#工具','#并发','#序列化','#微服务','#性能分析','#手册','#有道云','#标签','#模板','#百度云盘','#结构和算法','#计划','#迁移','#面试',],
            'itemHeight': 20,
            'width': 418
        }).AutoComplete('show');
    })
    function initArticle() {
        /*渲染对应的表格样式*/
        
            $(".post .pjax table").addClass("green_title");
        

        /*渲染打赏样式*/
        
        $("input[name=pay]").on("click", function () {
            if($("input[name=pay]:checked").val()=="weixin"){
                $(".shang_box .shang_payimg .pay_img").addClass("weixin_img");
            } else {
                $(".shang_box .shang_payimg .pay_img").removeClass("weixin_img");
            }
        })
        

        /*高亮代码块行号*/
        
        $('pre code').each(function(){
            var lines = $(this).text().trim().split('\n').length, widther='';
            if (lines>99) {
                widther = 'widther'
            }
            var $numbering = $('<ul/>').addClass('pre-numbering ' + widther).attr("unselectable","on");
            $(this).addClass('has-numbering ' + widther)
                    .parent()
                    .append($numbering);
            for(var i=1;i<=lines;i++){
                $numbering.append($('<li/>').text(i));
            }
        });
        

        /*访问数量*/
        
        $.getScript("//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js");
        

        /*代码高亮，行号对齐*/
        $('.pre-numbering').css('line-height',$('.has-numbering').css('line-height'));

        
        
    }

    /*打赏页面隐藏与展示*/
    
    function dashangToggle() {
        $(".shang_box").fadeToggle();
        $(".hide_box").fadeToggle();
    }
    

</script>

<!--加入行号的高亮代码块样式-->

<style>
    pre{
        position: relative;
        margin-bottom: 24px;
        border-radius: 10px;
        border: 1px solid #e2dede;
        background: #FFF;
        overflow: hidden;
    }
    code.has-numbering{
        margin-left: 30px;
    }
    code.has-numbering.widther{
        margin-left: 35px;
    }
    .pre-numbering{
        margin: 0px;
        position: absolute;
        top: 0;
        left: 0;
        width: 20px;
        padding: 0.5em 3px 0.7em 5px;
        border-right: 1px solid #C3CCD0;
        text-align: right;
        color: #AAA;
        background-color: #fafafa;
    }
    .pre-numbering.widther {
        width: 35px;
    }
</style>

<!--自定义样式设置-->
<style>
    
    
    .nav {
        width: 442px;
    }
    .nav.fullscreen {
        margin-left: -442px;
    }
    .nav-left {
        width: 120px;
    }
    
    
    @media screen and (max-width: 1468px) {
        .nav {
            width: 442px;
        }
        .nav.fullscreen {
            margin-left: -442px;
        }
        .nav-left {
            width: 150px;
        }
    }
    
    
    @media screen and (max-width: 1024px) {
        .nav {
            width: 442px;
            margin-left: -442px
        }
        .nav.fullscreen {
            margin-left: 0;
        }
        .nav .hide-list.fullscreen {
            left: 442px
        }
    }
    
    @media screen and (max-width: 426px) {
        .nav {
            width: 100%;
        }
        .nav-left {
            width: 100%;
        }
    }
    
    
    .nav-right .title-list nav a .post-title, .nav-right .title-list #local-search-result a .post-title {
        color: #383636;
    }
    
    
    .nav-right .title-list nav a .post-date, .nav-right .title-list #local-search-result a .post-date {
        color: #5e5e5f;
    }
    
    
    .nav-right nav a.hover, #local-search-result a.hover{
        background-color: #e2e0e0;
    }
    
    

    /*列表样式*/
    
    .post .pjax article .article-entry>ol, .post .pjax article .article-entry>ul, .post .pjax article>ol, .post .pjax article>ul{
        border: #e2dede solid 1px;
        border-radius: 10px;
        padding: 10px 32px 10px 56px;
    }
    .post .pjax article .article-entry li>ol, .post .pjax article .article-entry li>ul,.post .pjax article li>ol, .post .pjax article li>ul{
        padding-top: 5px;
        padding-bottom: 5px;
    }
    .post .pjax article .article-entry>ol>li, .post .pjax article .article-entry>ul>li,.post .pjax article>ol>li, .post .pjax article>ul>li{
        margin-bottom: auto;
        margin-left: auto;
    }
    .post .pjax article .article-entry li>ol>li, .post .pjax article .article-entry li>ul>li,.post .pjax article li>ol>li, .post .pjax article li>ul>li{
        margin-bottom: auto;
        margin-left: auto;
    }
    

    /* 背景图样式 */
    
    


    /*引用块样式*/
    

    /*文章列表背景图*/
    

    
</style>






<div class="mobile-menus-out" >

</div>
<div class="mobile-menus">
    
    
    
    <a class="dynamic-menu " target="_blank"  href="https://pgmanor.gitee.io/blog/">pgmanor</a>
    
    
    <a class="dynamic-menu " target="_blank"  href="https://www.iworkh.com/manualIt/Category/scopeDev/">iworkh</a>
    
    
    <a class="dynamic-menu " target="_blank"  href="https://gitee.com/iworkh">gitee</a>
    
</div>


<div style="position:absolute; bottom: 0; right: 0;">
    <iframe frameborder="no" border="0" marginwidth="0" marginheight="0" width=150 height=40 src="//music.163.com/outchain/player?type=2&id=1323150930&auto=0&height=32"></iframe>
</div>

</html>
